2014-12-16 1 views
0

나는 돛 0.10.5를 사용하고 앵글 - 돛을 가진 각진 프론트 엔드에있다.앵귤러 - 돛 websocket url undefined (ws : //www.undefined)

그것은 서버 측에서 다음과 같은 오류를 제공

는 때마다 내 프런트 엔드 측 컨트롤러 코드에서 $ sails.get

에 의해 API 호출 :

 
io.sails.url = 'http://localhost:1337'; 

     io.socket.get('http://localhost:1337/admin/v1/user/subscribe', function (body, response) { 
      console.log('Sails responded with: ', body); 
      console.log('with headers: ', response.headers); 
      console.log('and with status code: ', response.statusCode); 
     }); 

및 콘솔

 
Sails responded with: Object {} 
app.js:167 with headers: Object {} 
app.js:168 and with status code: 200 

입니다 하지만 백엔드 사이드 돛 콘솔에서 이런 오류가 발생합니다

 
debug: -------------------------------------------------------- 
debug: :: Fri Dec 19 2014 10:44:25 GMT+0530 (India Standard Time) 
debug: Environment : development 
debug: Port  : 1337 
debug: -------------------------------------------------------- 
error: Error: 
res.redirect() :: [socket.io] :: 
Cannot redirect socket to invalid location :: 'ws://www.undefinedhttp://localhost:1337/admin/v1/user/subscribe' 
    at Object.Err.invalidRedirect (C:\wamp\www\i-phone\i-phone\node_modules\sails\lib\hooks\sockets\lib\interpreter\interpret.js:33:14) 
    at ResStream.doRedirect (C:\wamp\www\i-phone\i-phone\node_modules\sails\lib\hooks\sockets\lib\interpreter\interpret.js:310:31) 
    at C:\wamp\www\i-phone\i-phone\node_modules\sails\lib\hooks\sockets\lib\interpreter\saveSessionAndThen.js:23:7 
    at C:\wamp\www\i-phone\i-phone\node_modules\sails\lib\hooks\session\index.js:59:17 

내 경로 파일은 다음과 같다 :

'get /admin/v1/user/subscribe': 'UserController.subscribe',

과의 UserController.js :

 
subscribe: function (req, res) { 

     console.log('aaaaaaaaaaaaaaaaaaaa') 

     User.find().exec(function(err,users){ 

      // subscribing this socket to User model classroom 
      User.subscribe(req.socket); 

      // subscribing this socket to User model instance room 
      User.subscribe(req.socket,users); 

      console.log('subscribe') 
     }) 


    } 

답변

1

어리석은 실수였습니다.

내 route.js에서 비 WWW 요청을 WWW 요청으로 리디렉션하고 있습니다. WS와

그리고 소켓 요청에 시작 : // 태그는 왜 그것은 당신으로 모든 일을 한 적은 상태

 
if(!req.isSocket){ 

    // redirect logic 
}else{ 
    next(); 
} 
1

서버와의 소켓 연결을 설정하는 경우 :

가 된 index.html에서 sails.io.js 포함합니다.
는 io.sails.url에 대한 전역 변수를 작성하고 당신은 무엇 URL에 연결하기 위해 항해 소켓 클라이언트에게 필요합니다 : 당신은 소켓 호출을 시작하기 전에

io.sails.url = 'http://localhost:1337'; 

이 어디를 넣어; 라이브러리는 전화를 걸기 전에 연결될 때까지 기다릴만큼 똑똑합니다. 소켓이 연결되어있는 경우

io.socket.get('http://localhost:1337/data', function (body, response) { 
    console.log('Sails responded with: ', body); 
    console.log('with headers: ', sailsResponseObject.headers); 
    console.log('and with status code: ', sailsResponseObject.statusCode); 
}); 

당신은 콘솔에서 볼 수 있어야합니다, 확인하려면 여부 "io.socket connected successfully." 메시지를 찾아 연결 소켓.

위 코드는 요청한대로 소켓 연결을 설정하는 코드입니다. 문제에 관한
, 당신은 당신이 명확하게 실행되지 않는 게시 된 일부 Code

+0

에 의해 해결된다

www.undefined로 리디렉션도되고 있습니다 먹으 렴 제안했지만, 여전히 작동하지 않습니다, 나는 당신이 볼 수있는 지금 내 질문을 업데이 트했습니다 ... –

1

컨트롤러 액션을 제공하시기 바랍니다 수 (당신은 당신의 콘솔에서 aaaaaaaaaaaaaaaaaaaa 로그를 볼 것). 다른 일부 코드가 실행 중이고 유효하지 않은 인수로 res.redirect을 호출 중입니다. 내 첫 번째 추측은 작업에 첨부 된 config/policies.js에 구성된 정책을 가지고있는 것입니다.

관련 문제