2016-06-21 3 views
1

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" 
} 

친절하게 내가 잘못 여기서 뭔가를하고있어 경우에 알려주세요. 귀하의 도움 감사 :

+0

당신이 당신의'package.json'을 넣을 수 (SSL 없음) http://test.herokuapp.com에 당신의 웹 사이트를 열? localhost 서버를 호출하는 스크립트가 있다고 생각합니다 –

+0

. 덧붙였다. –

+0

http : // test.herokuapp.com' 사이트의 http 버전을 열면 제대로 동작합니다. –

답변

0

귀하의 웹 사이트는 https에서 실행되지만 http는 소켓에서 실행됩니다. 초기 연결에 대한 보안 URL, 즉 대신 "http://" 사용 "https://"

var socket = io.connect('https://test.herokuapp.com', {secure: true}); 

를 사용하거나

+0

http로 열어도 여전히 localhost : 3000을 가리키고 있는데이 오류가 발생합니다. net :: ERR_CONNECTION_REFUSED –

+0

아마 하드 코딩 된 URL이 있습니다. 어딘가에, 프로젝트에 다른 io.connect 호출이 있는지 확인하십시오. 적어도 테스트 목적을 위해 명시 적으로 URL을 작성하십시오. –

관련 문제