- 
      
- 
        Save scsskid/136c5ac1445fce725fc8c8728c0e24e5 to your computer and use it in GitHub Desktop. 
Revisions
- 
        bencentra created this gist Feb 13, 2017 .There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ /* This module creates an HTTPS web server and serves static content from a specified directory on a specified port. To generate a new cert: openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 To remove the passphrase requirement: openssl rsa -in key.pem -out newkey.pem && mv newkey.pem key.pem Or just include the "passphrase" option when configuring the HTTPS server. Sources: - http://blog.mgechev.com/2014/02/19/create-https-tls-ssl-application-with-express-nodejs/ - https://expressjs.com/en/starter/static-files.html */ const fs = require('fs'); const https = require('https'); const express = require('express'); const app = express(); app.use(express.static(process.env.SERVE_DIRECTORY || '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 || '' }; const server = https.createServer(options, app); server.listen(process.env.SERVER_PORT || 8443);