Created
July 17, 2020 17:35
-
-
Save franTarkenton/604dbe2fc666637fa19d4e75513bbdae to your computer and use it in GitHub Desktop.
Node https web server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| create the client certificates: | |
| -------------------------------------------- | |
| openssl genrsa -out key.pem 2048 | |
| openssl req -new -key key.pem -out client.csr | |
| openssl x509 -req -in client.csr -signkey key.pem -out cert.pem | |
| run the web server: | |
| -------------------------------------------- | |
| node serve.js | |
| web server url: | |
| -------------------------------------------- | |
| https://localhost:3000 | |
| */ | |
| const fs = require('fs'); | |
| const https = require('https'); | |
| const express = require('express'); | |
| const app = express(); | |
| app.use(express.static('.' || 'dist')); | |
| app.get('/', function(req, res) { | |
| return res.end('<p>This server serves up static files.</p>'); | |
| }); | |
| const options = { | |
| key: fs.readFileSync('key.pem', 'utf8'), | |
| cert: fs.readFileSync('cert.pem', 'utf8'), | |
| passphrase: process.env.HTTPS_PASSPHRASE || 'password' | |
| }; | |
| const server = https.createServer(options, app); | |
| server.listen(3000 || 8443); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment