Simple socket.io server to handle the chat messages
-
to run the socket.io server:
yarn startornpm start -
the socket.io listen and emits the event
messagewith the object model:{ message: 'Hello socket.io server', user: 'username' }
-
start the server using the network ip address
-
add a CORS ( Cross-Origin Resource Sharing ) support ( MDN web docs )
app.use( ( req, res, next ) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
res.header('Access-Control-Allow-Headers', 'Content-Type');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
next();
});
app.options( ( req, res ) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
res.header('Access-Control-Allow-Headers', 'Content-Type');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.send(200);
});Deployed on now.sh (zeit.co/now)
Must have the start script defined on the package.json
-
Now's Command Line Interface | now docs
-
now(Deployment | now docs) - deploy the current folder content to thenow.shserver. -
now alias <ID> <ALIAS>(Aliases and Domains | now docs) - define a custom URL -
now alias rm <ALIAS>- remove a given alias -
now scale <ID> sfo 1 1(Global Scaling | now docs) - make sure to have only one instance of the deployment -
now remove <ID>- (Deployment Inactivity | now docs) remove the given instance by its<ID>
-
1 - now -e MODE=production - This commmand will give to you the <ID> of the deployed instance.
2 - now alias <ID> <ALIAS>
3 - now scale <ID> sfo 1 1
1 - now list - copy the <OLD_ID> assigned to the alias <ALIAS>
2 - now -e MODE=production - will deploy a new instance of the current folder content. This commmand will give to you the <NEW_ID> of the deployed instance.
3 - now alias <NEW_ID> <ALIAS>
4 - now remove <OLD_ID>
-
-
[GitHub] socketio / socket.io - Realtime application framework (Node.JS server)
-
-
Socket.IO Tutorial With io.js and Express | Program With Erik
-
[GitHub] indutny / node-ip - IP address tools for node.js