Node.js, Express.js, Socket.IO 및 React 기반 응용 프로그램을 Heroku에 배포하려고합니다.Heroku - Socket.IO 클라이언트가 항상 로컬 호스트에 연결
하지만 연결하는 동안 localhost를 지정하지 않은 경우에도 클라이언트 측에서 socket.io-client는 항상 localhost에 연결하는 것처럼 보입니다.
나는 브라우저 콘솔에서이 오류를 얻을 :
bundle.js:208 Mixed Content: The page at 'https://test.herokuapp.com/#/test?_k=v7l28t' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://localhost:3000/socket.io/?EIO=3&transport=polling&t=LLobEYP'. This request has been blocked; the content must be served over HTTPS.
내가 HTTP에 그것을 열려고하면 내가 연결이 오류가 거부 얻을 :
bundle.js:208 GET http://localhost:3000/socket.io/?EIO=3&transport=polling&t=LLpAsLm net::ERR_CONNECTION_REFUSED
가 여기 내 서버 소켓의 모양 무엇을 :
012 :var express = require('express');
var app = express();
var server = http.createServer(app);
var io = require('socket.io')(server);
server.listen(port);
io.on('connection', function(socket) {
socket.on('news', function(message) {
console.log("Responding with news");
io.sockets.emit('news', 'news');
});
});
그리고 여기에는 클라이언트 코드입니다 package.json 플러스
3,516,
var io = require('socket.io-client');
var socket = io.connect();
socket.on('connect', function() {
console.log('connected to server');
socket.emit('news', 'news');
});
:
는
{
"name": "test-socket",
"version": "1.0.0",
"private": true,
"scripts": {
"dev-server": "nodemon ./bin/www",
"dev-client": "watchify -t [ envify --NOVE_ENV development ] -t [ babelify --presets [ react es2015 ] ] public/javascripts/index.js -o public/javascripts/build/bundle.js -v",
"dev": "concurrently \"npm run dev-server\" \"npm run dev-client\"",
"build": "browserify -t [ envify --NOVE_ENV production ] -t [ babelify --presets [ react es2015 ] ] -g uglifyify public/javascripts/index.js -o public/javascripts/build/bundle.js",
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.13.2",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.13.1",
"fakeredis": "^1.0.3",
"jade": "~1.11.0",
"lodash": "^4.11.1",
"material-ui": "^0.15.0-beta.2",
"mongoose": "^4.5.0",
"morgan": "~1.6.1",
"passport": "^0.3.2",
"passport-http": "^0.3.0",
"passport-local": "^1.0.0",
"react": "^15.0.1",
"react-bootstrap": "^0.28.5",
"react-dom": "^15.0.1",
"react-router": "^2.4.1",
"react-tap-event-plugin": "^1.0.0",
"redis": "^2.6.2",
"serve-favicon": "~2.3.0",
"socket.io": "^1.4.6",
"socket.io-client": "^1.4.6",
"whatwg-fetch": "^0.11.0"
},
"devDependencies": {
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babelify": "^7.2.0",
"browserify": "^13.0.0",
"concurrently": "^2.1.0",
"envify": "^3.4.0",
"nodemon": "^1.9.2",
"uglifyify": "^3.0.1",
"watchify": "^3.7.0"
},
"description": "",
"main": "app.js",
"author": "Harsha Bhat",
"license": "ISC"
}
친절하게 내가 잘못 여기서 뭔가를하고있어 경우에 알려주세요. 귀하의 도움 감사 :
당신이 당신의'package.json'을 넣을 수 (SSL 없음) http://test.herokuapp.com에 당신의 웹 사이트를 열? localhost 서버를 호출하는 스크립트가 있다고 생각합니다 –
. 덧붙였다. –
http : // test.herokuapp.com' 사이트의 http 버전을 열면 제대로 동작합니다. –