2017-11-28 19 views
0

私のマシン上でローカルノードのjsサーバーを実行しており、ngrok.ioドメインを提供しています。httpエクスプレスルートの混在コンテンツエラー

localhost:3000またはhttp://1234.ngrok.ioを使用してWebブラウザでローカルに実行しても問題ありません。私は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ではありませんので、原因。これをどうすれば解決できますか?

これはこれは、エラーが発生した経路を持つ他のファイルであり、私の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 
} 

あなたが最初のファイルのoptionsオブジェクトでどのように見えるのかをhttpsで確認しましたが、これは502 Bad Gatewayで解決されました。

また、httpsだけを使用したいと思います。誰かがhttpを使用している場合、httpsにリダイレクトすることは可能ですか?

答えて

1

httpを使用してajaxリクエストを送信しているようですが、すべてのajaxコールがhttpsを超えていることを確認してください。

+0

とても簡単です。それは素晴らしい、ありがとう。 – WeSt

関連する問題