node.js - Express 3.0 HTTPS -


i have node.js express 3.0 application listens on port 3000 locally , 80 online, that's fine. need introduce ssl certificate.

i've looked @ many sources online they're dated, or work on port 443 or nothing. need listen on both 443 , 80 , re-direct requests 80 443.

are date examples of this?

i 2 distinct processes: insecure proxy server , secure server.

the insecure proxy listens on port 80 , responds requests 302 redirect secure server

insecure proxy

var http = require('http') var port = 80 var server = http.createserver(function (req, res) {   // change secure sever url   var redirecturl = 'https://www.google.com'   res.writehead(302, {     location: redirecturl   });   res.end(); }).listen(port, function () {   console.log('insecure proxy listening on port: ' + port) }) 

secure server

var https = require('https') var express = require('express') var fs = require('fs') var keyfilepath = '/path/to/key.pem' var certfilepath = '/path/to/cert.pem'  var app = express() // put express app config here // app.use(...) etc.  var port = 443 // standard https port var options = {   key: fs.readfilesync(keyfilepath, 'utf8'),   cert: fs.readfilesync(certfilepath, 'utf8') }  var server = https.createserver(options, app) server.listen(port, function () {   console.log('secure server listening on port: ' + port) }) 

note run both of these servers within single process more maintainable separate concerns distinct processes.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -