Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add socketIO to server
  • Loading branch information
mett-development committed Apr 10, 2022
1 parent 3985cb5 commit b0db6c5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/server/index.ts
@@ -1,9 +1,26 @@
import express from 'express';
import { createServer } from 'http';
import { Server } from 'socket.io';
import cors from 'cors';

const app = express();
app.use(cors());

const server = createServer(app);
const io = new Server(server, {
cors: {
origin: [/http:\/\/localhost:\d*/],
},
});

io.on('connection', (socket) => {
console.log(
`Socket ${socket.id} connected from origin: ${socket.handshake.headers.origin}`
);
socket.onAny((event, ...args) => {
console.log(event, args);
});
});

server.listen(5000, () => {
console.log(
Expand Down

0 comments on commit b0db6c5

Please sign in to comment.