Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change url SocketIoConfig for server side #65

Open
nicogaldo opened this issue May 31, 2018 · 2 comments
Open

Change url SocketIoConfig for server side #65

nicogaldo opened this issue May 31, 2018 · 2 comments

Comments

@nicogaldo
Copy link

nicogaldo commented May 31, 2018

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
Copy link

mimrank commented Oct 1, 2018

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
Copy link
Author

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);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants