-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (24 loc) · 683 Bytes
/
Copy pathserver.js
File metadata and controls
30 lines (24 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//server.js
import express from 'express';
import ViteExpress from 'vite-express';
import http from 'http';
import webSocket from 'socket.io';
const webSocketServer = webSocket.Server;
const app = express();
const server = http.createServer(app);
const io = new webSocketServer(server, {
cors: {
origin: '*',
},
});
io.on('connection', (socket) => {
console.log('we are connected');
socket.on('chat', (chat) => {
io.emit('chat', chat);
});
socket.on('disconnect', () => {
console.log('disconnected');
});
});
app.get('/message', (_, res) => res.send('Hello from express!'));
ViteExpress.listen(app, 3000, () => console.log('Server is listening...'));