【问题标题】:Routes not working after setting up HTTPS with Express使用 Express 设置 HTTPS 后路由不起作用
【发布时间】:2017-12-07 05:02:36
【问题描述】:

我正在尝试使用 HTTPS 连接设置我的应用程序。设置完成后,Express 会停止路由传入的请求。

var path = require('path');
var express = require('express');
var https = require('https');
var fs = require('fs');

var options = {
  key: fs.readFileSync('ssl-key.pem'),
  cert: fs.readFileSync('ssl-cert.pem')
}

var app = express();
var port = process.env.PORT || 3000;

https.createServer(options, app).listen(port, function() {
  console.log('listening on port ' + port);
});

app.get('*', function(req, res) {
  console.log('test');
  res.send('hello world')
});

我不断收到 ERR_EMPTY_RESPONSE

有人知道这是为什么吗?

感谢您的宝贵时间!

【问题讨论】:

标签: node.js express ssl https


【解决方案1】:

问题来了,因为你使用http://127.0.0.1:3000/或者(http://127.0.0.1:3000/),但是你需要使用https协议(https://localhost:3000/)证书,才能让node.js捕捉到这个请求

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-25
    • 2014-05-16
    • 2013-11-20
    • 2016-02-24
    • 1970-01-01
    • 2020-04-15
    • 2017-12-07
    相关资源
    最近更新 更多