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.

You are viewing an old version of this snippet. View the current version.
Revised by Aaron Bartell fa8ebbc

| | | - | - | - | - IBM i Hosting | Cybersource Toolkit for i | RPG-XML Suite | RPG-XML Suite | UPS Toolkit for i

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);
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.