WeS*_*eSt 1 https routes http node.js express
我在我的机器上运行本地 Node js 服务器,并为其提供一个ngrok.io域。
如果我在网络浏览器中本地运行它,localhost:3000则http://1234.ngrok.io一切正常。如果我调用它,httpS://1234.ngrok.io我会收到错误
Mixed Content: The page at 'https://1234.ngrok.io/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://localhost:3000/calculation'. This request has been blocked; the content must be served over HTTPS.
Run Code Online (Sandbox Code Playgroud)
由于路由不是http造成的。我怎样才能解决这个问题?
这是我的node.js 上的app.js
const express = require('express');
const app = express();
const https = require('https');
const http = require('http');
const fs = require('fs');
app.use('/', express.static(__dirname + '/../Client'));
var options = {
key: fs.readFileSync('./https_certificate/client-key.pem'),
cert: fs.readFileSync('./https_certificate/client-cert.pem')
};
app.listen(server_connection.port, () => {
console.log('Server started on port ' + server_connection.port);
//do stuff
});
//load the index.html from the server
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/../Client/index.html'));
});
Run Code Online (Sandbox Code Playgroud)
这是导致错误的路径的另一个文件:
const express = require('express');
const router = express();
router.post('/calculation', function(req, res) {
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试为 https 配置服务器,您如何options在第一个文件中的对象上看到这一点,但这在 502 Bad Gateway 中得到解决。
我也想只使用 https。如果有人使用http,是否可以重定向到https?
| 归档时间: |
|
| 查看次数: |
5695 次 |
| 最近记录: |