简体   繁体   English

webpack dev服务器混合内容错误

[英]webpack dev server mixed content error

I'm running React based website on Cloud9 using webpack-dev-server, so it serves content over https. 我正在使用webpack-dev-server在Cloud9上运行基于React的网站,因此它通过https提供内容。 The problem is that when I try to make some ajax (network) request to external http link, it gives the following error: 问题是当我尝试向外部http链接发出一些ajax(网络)请求时,它会出现以下错误:

Mixed Content: The page at 'https://...' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://...'. 混合内容:“https:// ...”页面是通过HTTPS加载的,但是请求了一个不安全的XMLHttpRequest端点“http:// ...”。 This request has been blocked; 此请求已被阻止; the content must be served over HTTPS. 内容必须通过HTTPS提供。

Is there any trick for webpack configuration to make it possible request data from http? 是否有任何技巧可以使webpack配置成为可能的http请求数据?

Probably there is no solution for webpack-dev-server, but the following is good for nodejs 可能没有webpack-dev-server的解决方案,但以下对nodejs有好处

app.use(function(req, res, next) {
    if (req.headers['x-forwarded-proto'] == 'https') {
        res.redirect('http://' + req.hostname + req.url);
    } else {
        next();
    }
});

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

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