-
-
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 | |
}); |
Looks to me that you are trying to handle a request hat is already handled.
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
});
I cannot get this to work. It reports Can't set headers after they are sent and node dies: