HTTPS with nodejs and connect

I am currently using nodejs with my HTTP server. Is there a way to activate HTTPS with a connection? I can not find documentation about this. Thanks.

Herry

+7
source share
2 answers

Instead of creating an http server, use an https server to connect:

 var fs = require('fs'); var connect = require('connect') //, http = require('http'); Use https server instead , https = require('https'); var options = { key: fs.readFileSync('ssl/server.key'), cert: fs.readFileSync('ssl/server.crt'), ca: fs.readFileSync('ssl/ca.crt') }; var app = connect(); https.createServer(options,app).listen(3000); 

See the documentation for https here and tls server (https is a subclass of tls) here

+12
source

From http://tjholowaychuk.com/post/18418627138/connect-2-0

HTTP and HTTPS

Previously connected. A server inherited from the main net.Server Node network. making it difficult to provide HTTP and HTTPS for your application. The result of connect () (formerly connect.createServer ()) is now just a JavaScript function. This means that you can omit the call to app.listen () and just pass the application to Node net.Server, as shown below:

 var connect = require('connect') , http = require('http') , https = require('https'); var app = connect() .use(connect.logger('dev')) .use(connect.static('public')) .use(function(req, res){ res.end('hello world\n'); }) http.createServer(app).listen(80); https.createServer(tlsOptions, app).listen(443); 

The same is true for express 3.0 as it inherits connect 2.0

+1
source

All Articles