├── .eslintignore ├── .eslintrc ├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── stale.yml ├── .gitignore ├── CODEOWNERS ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── client └── README.md ├── common └── models │ └── note.json ├── jmeter-tests.jmx ├── package.json └── server ├── boot ├── authentication.js └── root.js ├── component-config.json ├── config.json ├── datasources.json ├── middleware.json ├── model-config.json ├── private ├── certificate.pem ├── certrequest.csr ├── privatekey.pem └── test.p12 ├── server.js ├── ssl-config.js └── test-server.js /.eslintignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/strongloop/loopback-example-ssl/de204dedf4526b8a9372342294987f2fb7486c95/.eslintignore -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "loopback", 3 | "rules": { 4 | "max-len": ["error", 80, 4, { 5 | "ignoreComments": true, 6 | "ignoreUrls": true, 7 | "ignorePattern": "^\\s*var\\s.+=\\s*(require\\s*\\()|(/)" 8 | }] 9 | } 10 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 9 | 10 | # Description/Steps to reproduce 11 | 12 | 16 | 17 | # Link to reproduction sandbox 18 | 19 | 24 | 25 | # Expected result 26 | 27 | 30 | 31 | # Additional information 32 | 33 | 38 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | 3 | 4 | #### Related issues 5 | 6 | 12 | 13 | - connect to 14 | 15 | ### Checklist 16 | 17 | 22 | 23 | - [ ] New tests added or existing tests modified to cover all changes 24 | - [ ] Code conforms with the [style 25 | guide](http://loopback.io/doc/en/contrib/style-guide.html) 26 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 60 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 14 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | - security 9 | - critical 10 | - p1 11 | - major 12 | # Label to use when marking an issue as stale 13 | staleLabel: stale 14 | # Comment to post when marking an issue as stale. Set to `false` to disable 15 | markComment: > 16 | This issue has been automatically marked as stale because it has not had 17 | recent activity. It will be closed if no further activity occurs. Thank you 18 | for your contributions. 19 | # Comment to post when closing a stale issue. Set to `false` to disable 20 | closeComment: > 21 | This issue has been closed due to continued inactivity. Thank you for your understanding. 22 | If you believe this to be in error, please contact one of the code owners, 23 | listed in the `CODEOWNERS` file at the top-level of this repository. 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .project 3 | .DS_Store 4 | *.sublime* 5 | *.seed 6 | *.log 7 | *.csv 8 | *.dat 9 | *.out 10 | *.pid 11 | *.swp 12 | *.swo 13 | node_modules 14 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Lines starting with '#' are comments. 2 | # Each line is a file pattern followed by one or more owners, 3 | # the last matching pattern has the most precedence. 4 | 5 | # Alumni maintainers 6 | # @kjdelisle @loay @ssh24 @virkt25 7 | 8 | # Core team members from IBM 9 | * @jannyHou @b-admike @dhmlau @emonddr 10 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ### Contributing ### 2 | 3 | Thank you for your interest in `loopback-example-ssl`, an open source project 4 | administered by StrongLoop. 5 | 6 | Contributing to `loopback-example-ssl` is easy. In a few simple steps: 7 | 8 | * Ensure that your effort is aligned with the project's roadmap by 9 | talking to the maintainers, especially if you are going to spend a 10 | lot of time on it. 11 | 12 | * Make something better or fix a bug. 13 | 14 | * Adhere to code style outlined in the [Google C++ Style Guide][] and 15 | [Google Javascript Style Guide][]. 16 | 17 | * Sign the [Contributor License Agreement](https://cla.strongloop.com/agreements/strongloop/loopback-example-ssl) 18 | 19 | * Submit a pull request through Github. 20 | 21 | 22 | ### Contributor License Agreement ### 23 | 24 | ``` 25 | Individual Contributor License Agreement 26 | 27 | By signing this Individual Contributor License Agreement 28 | ("Agreement"), and making a Contribution (as defined below) to 29 | StrongLoop, Inc. ("StrongLoop"), You (as defined below) accept and 30 | agree to the following terms and conditions for Your present and 31 | future Contributions submitted to StrongLoop. Except for the license 32 | granted in this Agreement to StrongLoop and recipients of software 33 | distributed by StrongLoop, You reserve all right, title, and interest 34 | in and to Your Contributions. 35 | 36 | 1. Definitions 37 | 38 | "You" or "Your" shall mean the copyright owner or the individual 39 | authorized by the copyright owner that is entering into this 40 | Agreement with StrongLoop. 41 | 42 | "Contribution" shall mean any original work of authorship, 43 | including any modifications or additions to an existing work, that 44 | is intentionally submitted by You to StrongLoop for inclusion in, 45 | or documentation of, any of the products owned or managed by 46 | StrongLoop ("Work"). For purposes of this definition, "submitted" 47 | means any form of electronic, verbal, or written communication 48 | sent to StrongLoop or its representatives, including but not 49 | limited to communication or electronic mailing lists, source code 50 | control systems, and issue tracking systems that are managed by, 51 | or on behalf of, StrongLoop for the purpose of discussing and 52 | improving the Work, but excluding communication that is 53 | conspicuously marked or otherwise designated in writing by You as 54 | "Not a Contribution." 55 | 56 | 2. You Grant a Copyright License to StrongLoop 57 | 58 | Subject to the terms and conditions of this Agreement, You hereby 59 | grant to StrongLoop and recipients of software distributed by 60 | StrongLoop, a perpetual, worldwide, non-exclusive, no-charge, 61 | royalty-free, irrevocable copyright license to reproduce, prepare 62 | derivative works of, publicly display, publicly perform, 63 | sublicense, and distribute Your Contributions and such derivative 64 | works under any license and without any restrictions. 65 | 66 | 3. You Grant a Patent License to StrongLoop 67 | 68 | Subject to the terms and conditions of this Agreement, You hereby 69 | grant to StrongLoop and to recipients of software distributed by 70 | StrongLoop a perpetual, worldwide, non-exclusive, no-charge, 71 | royalty-free, irrevocable (except as stated in this Section) 72 | patent license to make, have made, use, offer to sell, sell, 73 | import, and otherwise transfer the Work under any license and 74 | without any restrictions. The patent license You grant to 75 | StrongLoop under this Section applies only to those patent claims 76 | licensable by You that are necessarily infringed by Your 77 | Contributions(s) alone or by combination of Your Contributions(s) 78 | with the Work to which such Contribution(s) was submitted. If any 79 | entity institutes a patent litigation against You or any other 80 | entity (including a cross-claim or counterclaim in a lawsuit) 81 | alleging that Your Contribution, or the Work to which You have 82 | contributed, constitutes direct or contributory patent 83 | infringement, any patent licenses granted to that entity under 84 | this Agreement for that Contribution or Work shall terminate as 85 | of the date such litigation is filed. 86 | 87 | 4. You Have the Right to Grant Licenses to StrongLoop 88 | 89 | You represent that You are legally entitled to grant the licenses 90 | in this Agreement. 91 | 92 | If Your employer(s) has rights to intellectual property that You 93 | create, You represent that You have received permission to make 94 | the Contributions on behalf of that employer, that Your employer 95 | has waived such rights for Your Contributions, or that Your 96 | employer has executed a separate Corporate Contributor License 97 | Agreement with StrongLoop. 98 | 99 | 5. The Contributions Are Your Original Work 100 | 101 | You represent that each of Your Contributions are Your original 102 | works of authorship (see Section 8 (Submissions on Behalf of 103 | Others) for submission on behalf of others). You represent that to 104 | Your knowledge, no other person claims, or has the right to claim, 105 | any right in any intellectual property right related to Your 106 | Contributions. 107 | 108 | You also represent that You are not legally obligated, whether by 109 | entering into an agreement or otherwise, in any way that conflicts 110 | with the terms of this Agreement. 111 | 112 | You represent that Your Contribution submissions include complete 113 | details of any third-party license or other restriction (including, 114 | but not limited to, related patents and trademarks) of which You 115 | are personally aware and which are associated with any part of 116 | Your Contributions. 117 | 118 | 6. You Don't Have an Obligation to Provide Support for Your Contributions 119 | 120 | You are not expected to provide support for Your Contributions, 121 | except to the extent You desire to provide support. You may provide 122 | support for free, for a fee, or not at all. 123 | 124 | 6. No Warranties or Conditions 125 | 126 | StrongLoop acknowledges that unless required by applicable law or 127 | agreed to in writing, You provide Your Contributions on an "AS IS" 128 | BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER 129 | EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES 130 | OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, OR 131 | FITNESS FOR A PARTICULAR PURPOSE. 132 | 133 | 7. Submission on Behalf of Others 134 | 135 | If You wish to submit work that is not Your original creation, You 136 | may submit it to StrongLoop separately from any Contribution, 137 | identifying the complete details of its source and of any license 138 | or other restriction (including, but not limited to, related 139 | patents, trademarks, and license agreements) of which You are 140 | personally aware, and conspicuously marking the work as 141 | "Submitted on Behalf of a Third-Party: [named here]". 142 | 143 | 8. Agree to Notify of Change of Circumstances 144 | 145 | You agree to notify StrongLoop of any facts or circumstances of 146 | which You become aware that would make these representations 147 | inaccurate in any respect. Email us at callback@strongloop.com. 148 | ``` 149 | 150 | [Google C++ Style Guide]: https://google.github.io/styleguide/cppguide.html 151 | [Google Javascript Style Guide]: https://google.github.io/styleguide/javascriptguide.xml 152 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) IBM Corp. 2014,2017. All Rights Reserved. 2 | Node module: loopback-example-ssl 3 | This project is licensed under the MIT License, full text below. 4 | 5 | -------- 6 | 7 | MIT license 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # loopback-example-ssl 2 | 3 | **⚠️ This LoopBack 3 example project is no longer maintained. Please refer to [LoopBack 4 Examples](https://loopback.io/doc/en/lb4/Examples.html) instead. ⚠️** 4 | 5 | An example to demonstrate how to set up SSL for LoopBack applications so you can call the REST APIs using HTTPS. 6 | 7 | ## Generate your own SSL certificate 8 | 9 | ```sh 10 | $ cd loopback-example-ssl/server/private 11 | $ openssl genrsa -out privatekey.pem 1024 12 | $ openssl req -new -key privatekey.pem -out certrequest.csr 13 | $ openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem 14 | ``` 15 | 16 | ## Load the SSL certificate 17 | 18 | In `ssl-config.js`: 19 | 20 | ```js 21 | var path = require('path'), 22 | fs = require("fs"); 23 | exports.privateKey = fs.readFileSync(path.join(__dirname, './private/privatekey.pem')).toString(); 24 | exports.certificate = fs.readFileSync(path.join(__dirname, './private/certificate.pem')).toString(); 25 | ``` 26 | 27 | ## Create the HTTPS server 28 | 29 | The code is in `server/server.js`: 30 | 31 | ```js 32 | 33 | var https = require('https'); 34 | var sslConfig = require('./ssl-config'); 35 | 36 | ... 37 | 38 | var options = { 39 | key: sslConfig.privateKey, 40 | cert: sslConfig.certificate 41 | }; 42 | ... 43 | 44 | server.listen(app.get('port'), function() { 45 | var baseUrl = (httpOnly? 'http://' : 'https://') + app.get('host') + ':' + app.get('port'); 46 | app.emit('started', baseUrl); 47 | console.log('LoopBack server listening @ %s%s', baseUrl, '/'); 48 | }); 49 | return server; 50 | ``` 51 | 52 | ## Start the application 53 | ```sh 54 | $ node ./server/server.js 55 | ``` 56 | ## Open the API explorer 57 | 58 | [https://localhost:3000/explorer](https://localhost:3000/explorer) 59 | 60 | ## References 61 | 62 | 1. [http://nodejs.org/api/https.html](http://nodejs.org/api/https.html) 63 | 64 | --- 65 | 66 | [More LoopBack examples](https://loopback.io/doc/en/lb3/Tutorials-and-examples.html) 67 | -------------------------------------------------------------------------------- /client/README.md: -------------------------------------------------------------------------------- 1 | ## Client 2 | 3 | This is the place for your application front-end files. 4 | -------------------------------------------------------------------------------- /common/models/note.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "note", 3 | "base": "PersistedModel", 4 | "properties": { 5 | "title": { 6 | "type": "string" 7 | }, 8 | "author": { 9 | "type": "string" 10 | }, 11 | "content": { 12 | "type": "string" 13 | }, 14 | "created": { 15 | "type": "date" 16 | }, 17 | "modified": { 18 | "type": "date" 19 | } 20 | }, 21 | "validations": [], 22 | "relations": {}, 23 | "acls": [], 24 | "methods": [] 25 | } -------------------------------------------------------------------------------- /jmeter-tests.jmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | false 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | continue 16 | 17 | false 18 | 1000 19 | 20 | 256 21 | 1 22 | 1391712243000 23 | 1391712243000 24 | false 25 | 26 | 27 | true 28 | 29 | 30 | 31 | 32 | 33 | 34 | localhost 35 | 3000 36 | 37 | 38 | http 39 | 40 | 41 | HttpClient4 42 | 4 43 | 44 | 45 | 46 | 47 | 48 | 49 | localhost 50 | 3000 51 | 52 | 53 | 54 | 55 | /api/notes 56 | GET 57 | true 58 | false 59 | true 60 | false 61 | false 62 | 63 | 64 | 65 | 66 | 67 | 200 68 | 69 | Assertion.response_code 70 | false 71 | 8 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | localhost 80 | 3000 81 | 82 | 83 | 84 | 85 | /api/notes?filter[limit]=100 86 | GET 87 | true 88 | false 89 | true 90 | false 91 | false 92 | 93 | 94 | 95 | 96 | 97 | 200 98 | 99 | Assertion.response_code 100 | false 101 | 8 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | localhost 110 | 3000 111 | 112 | 113 | http 114 | 115 | /api/notes/1 116 | GET 117 | true 118 | false 119 | true 120 | false 121 | false 122 | 123 | 124 | 125 | 126 | 127 | 200 128 | 129 | Assertion.response_code 130 | false 131 | 8 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | localhost 140 | 3000 141 | 142 | 143 | 144 | 145 | /api/routes 146 | GET 147 | true 148 | false 149 | true 150 | false 151 | false 152 | 153 | 154 | 155 | 156 | 157 | false 158 | 159 | saveConfig 160 | 161 | 162 | true 163 | true 164 | true 165 | 166 | true 167 | true 168 | true 169 | true 170 | false 171 | true 172 | true 173 | false 174 | false 175 | false 176 | false 177 | false 178 | false 179 | false 180 | false 181 | 0 182 | true 183 | 184 | 185 | 186 | 187 | 188 | 189 | false 190 | 191 | saveConfig 192 | 193 | 194 | true 195 | true 196 | true 197 | 198 | true 199 | true 200 | true 201 | true 202 | false 203 | true 204 | true 205 | false 206 | false 207 | false 208 | false 209 | false 210 | false 211 | false 212 | false 213 | 0 214 | true 215 | 216 | 217 | 218 | 219 | 220 | 221 | false 222 | 223 | saveConfig 224 | 225 | 226 | true 227 | true 228 | true 229 | 230 | true 231 | true 232 | true 233 | true 234 | false 235 | true 236 | true 237 | false 238 | false 239 | false 240 | false 241 | false 242 | false 243 | false 244 | false 245 | 0 246 | true 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "loopback-example-ssl", 3 | "version": "2.1.0", 4 | "main": "server/server.js", 5 | "engines": { 6 | "node": ">=8" 7 | }, 8 | "license": "MIT", 9 | "scripts": { 10 | "lint": "eslint .", 11 | "lint:fix": "eslint . --fix", 12 | "posttest": "npm run lint" 13 | }, 14 | "dependencies": { 15 | "async": "~0.9.0", 16 | "compression": "^1.6.2", 17 | "loopback": "^3.0.0", 18 | "loopback-boot": "^2.6.5", 19 | "loopback-component-explorer": "^6.3.1", 20 | "serve-favicon": "^2.0.1", 21 | "strong-error-handler": "^3.2.0" 22 | }, 23 | "devDependencies": { 24 | "eslint": "^6.1.0", 25 | "eslint-config-loopback": "^13.1.0" 26 | }, 27 | "author": "IBM Corp." 28 | } 29 | -------------------------------------------------------------------------------- /server/boot/authentication.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2014,2016. All Rights Reserved. 2 | // Node module: loopback-example-ssl 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | 'use strict'; 7 | 8 | module.exports = function enableAuthentication(server) { 9 | // enable authentication 10 | server.enableAuth(); 11 | }; 12 | -------------------------------------------------------------------------------- /server/boot/root.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2014,2016. All Rights Reserved. 2 | // Node module: loopback-example-ssl 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | 'use strict'; 7 | 8 | module.exports = function(server) { 9 | // Install a `/` route that returns server status 10 | const router = server.loopback.Router(); 11 | router.get('/', server.loopback.status()); 12 | server.use(router); 13 | }; 14 | -------------------------------------------------------------------------------- /server/component-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "loopback-component-explorer": { 3 | "mountPath": "/explorer" 4 | } 5 | } -------------------------------------------------------------------------------- /server/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "restApiRoot": "/api", 3 | "host": "0.0.0.0", 4 | "port": 3000, 5 | "url": "https://localhost:3000/", 6 | "swagger": { 7 | "protocol": "https" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /server/datasources.json: -------------------------------------------------------------------------------- 1 | { 2 | "db": { 3 | "name": "db", 4 | "connector": "memory" 5 | } 6 | } -------------------------------------------------------------------------------- /server/middleware.json: -------------------------------------------------------------------------------- 1 | { 2 | "initial:before": { 3 | "loopback#favicon": {} 4 | }, 5 | "initial": { 6 | "compression": {} 7 | }, 8 | "session": { 9 | }, 10 | "auth": { 11 | }, 12 | "parse": { 13 | }, 14 | "routes": { 15 | "loopback#rest": { 16 | "paths": ["${restApiRoot}"] 17 | } 18 | }, 19 | "files": { 20 | }, 21 | "final": { 22 | "loopback#urlNotFound": {} 23 | }, 24 | "final:after": { 25 | "strong-error-handler": {} 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /server/model-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "sources": [ 4 | "../common/models", 5 | "./models" 6 | ] 7 | }, 8 | "User": { 9 | "dataSource": "db" 10 | }, 11 | "AccessToken": { 12 | "dataSource": "db", 13 | "public": false 14 | }, 15 | "ACL": { 16 | "dataSource": "db", 17 | "public": false 18 | }, 19 | "RoleMapping": { 20 | "dataSource": "db", 21 | "public": false 22 | }, 23 | "Role": { 24 | "dataSource": "db", 25 | "public": false 26 | }, 27 | "note": { 28 | "dataSource": "db", 29 | "public": true 30 | } 31 | } -------------------------------------------------------------------------------- /server/private/certificate.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIB/TCCAWYCCQDK5QPVVgU3jzANBgkqhkiG9w0BAQUFADBDMQswCQYDVQQGEwJV 3 | UzETMBEGA1UECBMKQ2FsaWZvcm5pYTESMBAGA1UEBxMJU2FuIE1hdGVvMQswCQYD 4 | VQQKEwJTTDAeFw0xNDAxMzExODQzNTFaFw0xNDAzMDIxODQzNTFaMEMxCzAJBgNV 5 | BAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRIwEAYDVQQHEwlTYW4gTWF0ZW8x 6 | CzAJBgNVBAoTAlNMMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+kN7aXyge 7 | Op2/bB+GrER7AiTQuizpwK19whemmFTtsu79JgWSADkdUfhPeJrmBPHJnhGWskLU 8 | oWyqLYM1GCfDNAyojmyW9ZFwCCiLaUuHn+Usg7+vdcKIGV8MKWrjojtlQatsLa2K 9 | 01v9CWbaJz9p0VNLUw1l9yh5TZQCroo87QIDAQABMA0GCSqGSIb3DQEBBQUAA4GB 10 | AKAEe950tCwT7ysq6KvlEDLrYu9wqjgd/VaXub6TX/HOT5n5naxoOJJpDDuTfUhX 11 | KmBl3hpm6zvSDCr4X40LIZJVIoKvLmJwkVZ8Ywk10v6qRRRx9djycB2AYPBmXUIX 12 | IaVfh2k2z6Kg191s7BKZREw0xRQh4giNKls9FsiZeM8E 13 | -----END CERTIFICATE----- 14 | -------------------------------------------------------------------------------- /server/private/certrequest.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIBgjCB7AIBADBDMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTES 3 | MBAGA1UEBxMJU2FuIE1hdGVvMQswCQYDVQQKEwJTTDCBnzANBgkqhkiG9w0BAQEF 4 | AAOBjQAwgYkCgYEAvpDe2l8oHjqdv2wfhqxEewIk0Los6cCtfcIXpphU7bLu/SYF 5 | kgA5HVH4T3ia5gTxyZ4RlrJC1KFsqi2DNRgnwzQMqI5slvWRcAgoi2lLh5/lLIO/ 6 | r3XCiBlfDClq46I7ZUGrbC2titNb/Qlm2ic/adFTS1MNZfcoeU2UAq6KPO0CAwEA 7 | AaAAMA0GCSqGSIb3DQEBBQUAA4GBAIF7wZ+4Bb+f0SEY79qFIrj4yniwXoLqSmyD 8 | 3ak5+OjVIhQr9UkdXalr3cny0Kdj6pMw9VyoogLUiMJd/bVYJ1j4WZ0KpcKrJeQ0 9 | xUA4XopSih9HQSfphMm6fYljGeSjkorOUJ7lbzujLKvUsl38T21MEP5M/2RzfsP2 10 | ytyZZdO2 11 | -----END CERTIFICATE REQUEST----- 12 | -------------------------------------------------------------------------------- /server/private/privatekey.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXQIBAAKBgQC+kN7aXygeOp2/bB+GrER7AiTQuizpwK19whemmFTtsu79JgWS 3 | ADkdUfhPeJrmBPHJnhGWskLUoWyqLYM1GCfDNAyojmyW9ZFwCCiLaUuHn+Usg7+v 4 | dcKIGV8MKWrjojtlQatsLa2K01v9CWbaJz9p0VNLUw1l9yh5TZQCroo87QIDAQAB 5 | AoGAD6w+h9s3o3TSsIGl/h+A6lT8ziXht7/fBO7Hny38HiiPO0a7Qoy+JckuEOss 6 | YiqZ8CkN7UTv9ijolP51QhKggmsHvk/wX79xnHmQLgl/mY0yPxH6KDBihHK3J+lu 7 | HnH9Dk+b2VOx63+6nmF38X0GPBeQR7HBIcTl8VgZmmwdr0kCQQDraPL124EeLjGu 8 | AQsfeOZaZUain83jc1FouBeJ3j3X3iWKlyuZgD3e+ALV+U6Fzv379x9eBmUwGap2 9 | cEYt4mXbAkEAzzvSG7dhpxFdjF+QjAxt8E1x+udakGBFvCoz9EeYZEXd8CkzZZKB 10 | BrfZVHgjkd+yhCAT7D+8MV271xg3uAe21wJBAOYhM5p7Gg8p83D6HiiHJRFrfhDO 11 | jhRzEDuB86jYdLaJuUNxorKttk45P3R0Ano2rv3ZSHW/ZL4P6R9dhI2ojA8CQQCK 12 | KtlAL3kFObfEcqbeKR9Xm1sGLSAdqIJ2HTE8ikuZd1es2ttwukgaYZOeFOeqR5ov 13 | K2/9ENV5mIQ3uebUZRhLAkAWmRDcafDV1lXnzqGMVvDWwQ9UoCnJueDJCFLqK+ra 14 | zo+8drKU+VqY6ymQpPPYj2fUaYgwqvTvRxykzZjS/0MB 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /server/private/test.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/strongloop/loopback-example-ssl/de204dedf4526b8a9372342294987f2fb7486c95/server/private/test.p12 -------------------------------------------------------------------------------- /server/server.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2014,2016. All Rights Reserved. 2 | // Node module: loopback-example-ssl 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | 'use strict'; 7 | 8 | const loopback = require('loopback'); 9 | const boot = require('loopback-boot'); 10 | 11 | const http = require('http'); 12 | const https = require('https'); 13 | const sslConfig = require('./ssl-config'); 14 | 15 | const app = module.exports = loopback(); 16 | 17 | // boot scripts mount components like REST API 18 | boot(app, __dirname); 19 | 20 | app.start = function(httpOnly) { 21 | if (httpOnly === undefined) { 22 | httpOnly = process.env.HTTP; 23 | } 24 | let server = null; 25 | if (!httpOnly) { 26 | const options = { 27 | key: sslConfig.privateKey, 28 | cert: sslConfig.certificate, 29 | }; 30 | server = https.createServer(options, app); 31 | } else { 32 | server = http.createServer(app); 33 | } 34 | server.listen(app.get('port'), function() { 35 | const baseUrl = (httpOnly ? 'http://' : 'https://') + app.get('host') + ':' + app.get('port'); 36 | app.emit('started', baseUrl); 37 | console.log('LoopBack server listening @ %s%s', baseUrl, '/'); 38 | if (app.get('loopback-component-explorer')) { 39 | const explorerPath = app.get('loopback-component-explorer').mountPath; 40 | console.log('Browse your REST API at %s%s', baseUrl, explorerPath); 41 | } 42 | }); 43 | return server; 44 | }; 45 | 46 | // start the server if `$ node server.js` 47 | if (require.main === module) { 48 | app.start(); 49 | } 50 | -------------------------------------------------------------------------------- /server/ssl-config.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2014,2016. All Rights Reserved. 2 | // Node module: loopback-example-ssl 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | 'use strict'; 7 | 8 | const path = require('path'); 9 | const fs = require('fs'); 10 | 11 | exports.privateKey = fs.readFileSync(path.join(__dirname, './private/privatekey.pem')).toString(); 12 | exports.certificate = fs.readFileSync(path.join(__dirname, './private/certificate.pem')).toString(); 13 | -------------------------------------------------------------------------------- /server/test-server.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2014,2016. All Rights Reserved. 2 | // Node module: loopback-example-ssl 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | 'use strict'; 7 | 8 | /** 9 | * Run `node import.js` to import the test data into the db. 10 | */ 11 | const async = require('async'); 12 | const app = require('./server'); 13 | const db = app.dataSources.db; 14 | 15 | const notes = [ 16 | ]; 17 | 18 | for (let i = 0; i < 500; i++) { 19 | notes.push({author: 'Author' + i, title: 'Blog ' + i, 20 | content: 'Nice content ' + i, created: new Date(), modified: new Date()}); 21 | } 22 | 23 | function importData(Model, data, cb) { 24 | // console.log('Importing data for ' + Model.modelName); 25 | Model.destroyAll(function(err) { 26 | if (err) { 27 | cb(err); 28 | return; 29 | } 30 | async.each(data, function(d, callback) { 31 | Model.create(d, callback); 32 | }, cb); 33 | }); 34 | } 35 | 36 | async.series( 37 | [ 38 | function(cb) { 39 | db.autoupdate(cb); 40 | }, 41 | importData.bind(null, app.models.note, notes), 42 | ], function(err, results) { 43 | if (err) { 44 | console.error(err); 45 | } else { 46 | console.log('Done'); 47 | } 48 | } 49 | ); 50 | 51 | app.start(); 52 | 53 | --------------------------------------------------------------------------------