Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Created April 5, 2011 13:35
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save 3rd-Eden/903596 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/903596 to your computer and use it in GitHub Desktop.
// Build the https based part & read the key and crt file that is required to encrypte the server / client connection
var ssl = https.createServer({
key: fs.readFileSync( "./ssl/ssl.private.key" ).toString()
, cert: fs.readFileSync( "./ssl/ssl.crt" ).toString()
});
// This is the part what it's all about, we are going to route all
// https based requires to the default app handler
ssl.addListener( "request", function sllRequestListener( req, res ){
req.ssl = true; // just add an extra flag so we can see if it was forwarded from https
app.emit( "request", req, res ); // app is my express instance
});
@3rd-Eden
Copy link
Author

3rd-Eden commented Jun 5, 2012

Looks to me that you are trying to handle a request hat is already handled.

@mbabuskov
Copy link

Here's my complete code:

var sys = require('util'),
express = require('express'),
fs = require('fs'),
connect = require('connect')
;
var pkey = fs.readFileSync('oated.key').toString();
var cert = fs.readFileSync('oated.com.crt').toString();
var dad1 = fs.readFileSync('gd_bundle1.crt').toString();
var dad2 = fs.readFileSync('gd_bundle2.crt').toString();
var apps = express.createServer({key: pkey, cert: cert, ca: [dad1,dad2]});
var app = express.createServer();
apps.listen(443);
app.listen(80);

app.configure(function () {
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(connect.static('public'));
});

app.get('/', function(req, res){
if (req.ssl)
res.end('Hello HTTPS');
else
res.end('Hello HTTP');
});

apps.addListener( "request", function sslRequestListener( req, res ){
req.ssl = true; // just add an extra flag so we can see if it was forwarded from https
app.emit( "request", req, res ); // app is my express instance
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment