I'm currently using nodejs with connect as my HTTP server.
Is there anyway to activate HTTPS with connect?
I cannot find any documentation about it.
HTTPS with nodejs and connect
Asked Answered
nodejs.org/api/https.html#https_class_https_server. –
Loosejointed
Check out this blog post on Connect 2.0 tjholowaychuk.com/post/18418627138/connect-2-0 –
Intellectualism
Instead of creating http
server, use https
server for 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
From http://tjholowaychuk.com/post/18418627138/connect-2-0
HTTP and HTTPS
Previously connect.Server inherited from Node’s core net.Server, this made it difficult to provide both HTTP and HTTPS for your application. The result of connect() (formerly connect.createServer()) is now simply a JavaScript Function. This means that you may omit the call to app.listen(), and simply pass app to a Node net.Server as shown here:
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 since it inherits connect 2.0
© 2022 - 2024 — McMap. All rights reserved.