簡體   English   中英

Heroku混合內容HTTPS / HTTP問題

[英]Heroku Mixed content HTTPS/HTTP issue

我將我的應用程序部署到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,但這沒有幫助。 我認為這不會起作用哈哈。 我認為它可能是谷歌字體,但這是鏈接“//fonts.googleapis.com/css?family=xxx+xxx+xxx”,這應該是很好的HTTPS。 有什么想法或建議嗎?

在您的app.js或服務中,或者您在應用程序中調用服務器的地方,請將地址從localhost:3000更改為https://***.herokuapp.com:443 / yourendpoint。 所以喜歡

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

“//***.herokuapp.com:443”也應該有用

https在443.也許,更改您的服務器以偵聽該端口而不是8080。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM