KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Can I create an Express server listening on both HTTP and HTTPS, with the same routes and the same middlewares? Currently I do this with Express on HTTP, with stunnel tunneling HTTPS to Express, but I prefer a pure Node solution. I can do it with this code, but using the handle method that is marked as private: var express = require( 'express' ) , https = require("https") , fs = require( 'fs' ); var app = express.createServer(); // init routes and middlewares app.listen( 80 ); var privateKey = fs.readFileSync( 'privatekey.pem' ).toString(); var certificate = fs.readFileSync( 'certificate.pem' ).toString(); var options = {key: privateKey, cert: certificate}; https.createServer( options, function(req,res) { app.handle( req, res ); } ).listen( 443 );
Tags (comma-separated)
Save Edits
Cancel