2

how can i integrate ssl in express:

var credentials = {key: privateKey, cert: certificate};

in this code to enable https?:

var express = require('express');
var app = express();

app.use(express.static('webcontent', {'index': ['client.html']}));

var server = app.listen(8000, function () {
  var host = server.address().address;
  var port = server.address().port;
  console.log('Webserver app listening at http://%s:%s', host, port);
});

the problem is, that i use express.static. and I dont find any sulution how to use it with https.

Cracker0dks
  • 2,422
  • 1
  • 24
  • 39
  • possible duplicate of [How do I setup a SSL certs for an express.js server?](http://stackoverflow.com/questions/11804202/how-do-i-setup-a-ssl-certs-for-an-express-js-server) – smnbbrv May 07 '15 at 11:26
  • 1
    no they are not using express.static – Cracker0dks May 07 '15 at 11:47

1 Answers1

1

To enable HTTPS you need to do the following.

var express = require('express');
var https = require('https');
var http = require('http');
var app = express();

http.createServer(app).listen(80);
https.createServer(options, app).listen(443);

app.use(express.static('webcontent', {'index': ['client.html']}));
Jeff Sloyer
  • 4,899
  • 1
  • 24
  • 48