Snippets
litmis Node.js listening on two ports for the purposes of forwarding non-secure traffic to a secure one. Note SSL wasn't included and instead just traffic forwarding concept.
Created by
Aaron Bartell
last modified
Andrei Tyuhai
Node.js Listening On Two Ports
Node.js listening on two ports for the purposes of forwarding non-secure traffic to a secure one. Note SSL wasn't included and instead just traffic forwarding concept.
var http = require('http') var os = require('os') http.createServer(function(req, res) { var new_loc = 'http://' + os.hostname() + ':8443' console.log('new_loc:%s', new_loc) res.writeHead(301, {Location: new_loc} ); res.end(); }).listen(8080); http.createServer(function(req, res) { console.log('secure') res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Response 8443\n'); }).listen(8443);
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.