bougarfaoui / ng-socket-io

Socket.IO module for Angular
MIT License
254 stars 57 forks source link

Change url SocketIoConfig for server side #65

Open nicogaldo opened 6 years ago

nicogaldo commented 6 years ago

I made the deploy in Heroku, but what url should I configure?

app.module.ts (Angular hosted in other server)

import { SocketIoModule, SocketIoConfig } from 'ng-socket-io';
const config: SocketIoConfig = { url: 'http://myapp-backend.herokuapp.com:55353', options: {} };

app.js (node.js hosted in heroku server)

var app = express();

var port = process.env.PORT || 8080;
//var port = 3000;

// Notification Real Time 
// http://4dev.tech/2017/12/tutorial-creating-a-realtime-notification-system-in-angular-and-nodejs/
var http = require('http');
var server = http.createServer(app);
var io = require('socket.io').listen(server);
io.set("origins", "*:*");
server.listen(8000);

io.on('connection', function(socket) {
  socket.on('create notification', function( data ){
    socket.broadcast.emit('new notification', data);
  });
});

In chrome console get the error: GET http://myapp-backend.herokuapp.com:55353/socket.io/?EIO=3&transport=polling&t=MEtzh25 0 ()

mimrank commented 5 years ago

we also face this issue.

In Chrome the connection goes to http://141.XX.XX.25/socket.io/ but on Android, it tries to connect to http://file/socket.io/

How can I change it?

nicogaldo commented 5 years ago

This is my actual code and works.

var express = require('express');
var app = express();
var server = require('http').createServer(app);

var io = require('socket.io')(server);
io.on('connection', function(socket) {
  socket.on('create notification', function( data ) {
    socket.broadcast.emit('new notification', data);
  });
});

var PORT = process.env.PORT || 8080;
//var PORT = 3000;
server.listen(PORT, ()=> {
  console.log('Node/Express: \x1b[32m%s\x1b[0m', 'online - port: '+ PORT);
});