Skip to content

Latest commit

 

History

History
102 lines (55 loc) · 3.46 KB

File metadata and controls

102 lines (55 loc) · 3.46 KB

React Socket Simple Chat - Socket.io Server

Simple socket.io server to handle the chat messages

  • to run the socket.io server: yarn start or npm start

  • the socket.io listen and emits the event message with the object model: { message: 'Hello socket.io server', user: 'username' }

tip to make socket.io server accepts multiple devices connections

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

Server deployment on now.sh

Deployed on now.sh (zeit.co/now)

Requirement

Must have the start script defined on the package.json

Commands

Deployment steps

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

Re-deployment steps

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>

Links

Dependencies