【问题标题】:Heroku Mixed content HTTPS/HTTP issueHeroku 混合内容 HTTPS/HTTP 问题
【发布时间】:2016-09-04 21:11:11
【问题描述】:

我将我的应用部署到 Heroku,但我在 Chrome 控制台中不断收到此错误:

bundle.js:11892 Mixed Content: The page at 'https://***.herokuapp.com/#/login' 
was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint    
'http://localhost:3000/login'. This request has been blocked; the content must 
be served over HTTPS.(anonymous function) @ bundle.js:11892sendReq @ 
bundle.js:11653serverRequest @ bundle.js:11363processQueue @ 
bundle.js:16097(anonymous function) @ bundle.js:16113Scope.$eval @ 
bundle.js:17365Scope.$digest @ bundle.js:17181Scope.$apply @   
bundle.js:17473(anonymous function) @ bundle.js:25159defaultHandlerWrapper @ 
bundle.js:3592eventHandler @ bundle.js:3580
bundle.js:11892 XMLHttpRequest cannot load http://localhost:3000/login. Failed     
to start loading.

这是我的服务器文件:

let express = require('express');
let app = express();
let publicRouter = express.Router();
let apiRouter = express.Router();
let models = require(__dirname + '/models');
let bodyParser = require('body-parser');
let morgan = require('morgan');
let config = require(__dirname + '/config/env.js');

app.use(express.static(__dirname + '/build'));

app.use((req, res, next) => {
 res.header('Access-Control-Allow-Origin', 'http://localhost:8080');
 res.header('Access-Control-Allow-Headers', 'Content-Type, token, authorization');
 res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
 next();
})

require(__dirname + '/routes/auth-routes')(publicRouter, models);
require(__dirname + '/routes/users-routes')(apiRouter, models);
require(__dirname + '/routes/questions-routes')(apiRouter, models);
require(__dirname + '/routes/scores-routes')(apiRouter, models);

app.use(bodyParser.json());
app.use('/', publicRouter);
app.use('/api', apiRouter);
app.use(morgan('dev'));

app.listen(config.PORT, () => {
  console.log('server started on port ' + config.PORT);
});

我尝试将所有 localhost:3000 路由更改为 https,但这没有帮助。我还以为不行哈哈我认为它可能是 google 字体,但这是链接“//fonts.googleapis.com/css?family=xxx+xxx+xxx”,应该适合 HTTPS。有什么想法或建议吗?

【问题讨论】:

    标签: javascript heroku https mean-stack


    【解决方案1】:

    在您的 app.js 或服务中,或者您在应用程序中调用服务器的位置,将地址从 localhost:3000 更改为 https://***.herokuapp.com:443/yourendpoint。所以喜欢

    $http.get("https://***.herokuapp.com:443/api).then(function(response) {
    ...some code...;
    })
    

    “//***.herokuapp.com:443”也应该可以工作

    【讨论】:

    • 我的本地 API 路径类似于...http://gisapi-web-staging-1636833739.eu-west-1.elb.amazonaws.com/v2。那么部署到heroku时我的路径应该是什么?
    【解决方案2】:

    https 在 443 上。也许,将您的服务器更改为侦听该端口而不是 8080。

    【讨论】:

      猜你喜欢
      • 2015-08-13
      • 1970-01-01
      • 1970-01-01
      • 2016-04-16
      • 2020-08-18
      • 2021-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多