Express使用Https服务器

时间:2022-06-14 15:07:01
var fs = require('fs');
var http = require('http');
var https = require('https');
var privateKey = fs.readFileSync('sslcert/server.key', 'utf8');
var certificate = fs.readFileSync('sslcert/server.crt', 'utf8'); var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express(); // your express configuration here var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app); httpServer.listen(8080);
httpsServer.listen(8443);