|
1 | 1 | # HTTPS server running on localhost |
| 2 | +Run an express server on localhost with HTTP2 and SSL for free. |
| 3 | + |
| 4 | +Serve static files or import as module in your project |
| 5 | + |
2 | 6 |
|
3 | 7 | ### Install and trust the certificate |
4 | 8 | Add the root certificate we just generated to your list of trusted certificates. |
5 | 9 | This step depends on the operating system you're running: |
| 10 | + |
6 | 11 | - Mac OS: open Keychain Access, choose System from the left navigation bar, choose "Import items..." from the File app |
7 | 12 | menu and select the file. Then double-click on the certificate and select always-trust in the Trust panel. |
| 13 | + |
8 | 14 | - Linux: Depending on your Linux distribution, you can use `trust`, `update-ca-certificates` or another command to mark |
9 | 15 | the generated root certificate as trusted. |
10 | 16 |
|
| 17 | + |
11 | 18 | ### Run |
12 | | -1. Edit [server.js](server.js): |
13 | | - - serve static files with `app.use(express.static('<path-to-serve>'))` |
14 | | - - use express as backend, i.e.: `app.get('/', (req, res) => res.send('Hello World!'))` |
15 | | -2. Install dependency with `npm install` |
16 | | -3. Run with `sudo npm start` or `sudo node serve.js` (root required to use port 443) |
17 | 19 |
|
18 | | -### License |
19 | | -[AGPL-3.0](LICENSE) |
| 20 | +#### Use standalone |
| 21 | +From terminal navigate into the folder and run `sudo npm install -g` to install this tool globally. |
20 | 22 |
|
21 | | -**Thanks to:** [Daksh Shah](https://github.com/dakshshah96) |
| 23 | +Then serve static file with `sudo serve <static-path>`. |
| 24 | + |
| 25 | + |
| 26 | +#### Use as module |
| 27 | +Just require this module. It will start the server automatically. |
| 28 | + |
| 29 | +For example, put in your index.js file: |
| 30 | +``` |
| 31 | +const app = require('./index.js') |
| 32 | +app.get('/', (req, res) => res.send('Hello World!')) |
| 33 | +``` |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +### License |
| 38 | +[AGPL-3.0](LICENSE) |
0 commit comments