Created
April 5, 2011 13:35
-
-
Save 3rd-Eden/903596 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
});