简体   繁体   English

如何在Express 4.x上启用https(使用express.static)

[英]How to enable https on express 4.x (with express.static)

how can i integrate ssl in express: 我如何在Express中集成ssl:

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

in this code to enable https?: 在此代码中启用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. 问题是,我使用express.static。 and I dont find any sulution how to use it with https. 我找不到任何解决方案如何与https一起使用。

To enable HTTPS you need to do the following. 要启用HTTPS,您需要执行以下操作。

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']}));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM