Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js http express路由的混合内容错误_Node.js_Http_Express_Https_Routes - Fatal编程技术网

Node.js http express路由的混合内容错误

Node.js http express路由的混合内容错误,node.js,http,express,https,routes,Node.js,Http,Express,Https,Routes,我正在我的机器上运行一个本地节点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 'ht

我正在我的机器上运行一个本地节点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.
原因是路由不是http。我怎样才能解决这个问题

这是my 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'));
});
这是导致错误的另一个路由文件:

const express = require('express');
const router = express();
router.post('/calculation', function(req, res) {
 //do stuff
}
我已经尝试将服务器配置为https,您可以在第一个文件中的options对象上看到什么,但这在502坏网关中得到了解决


我还想使用https。如果有人使用http,是否可以重定向到https?

您似乎正在使用http向服务器发送ajax请求,请确保所有ajax调用都通过https来避免此错误。

您似乎正在使用http向服务器发送ajax请求,确保所有ajax调用都是通过https进行的,以避免此错误