-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
34 lines (27 loc) · 890 Bytes
/
server.ts
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
31
32
33
34
import express from 'express';
import axios from 'axios';
import next from 'next';
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
import http from 'http';
import { Server } from 'socket.io';
app.prepare().then(async () => {
const server = express();
const httpServer = http.createServer(server);
const io = new Server(httpServer);
io.on('connection', (socket) => {
console.log('Client connected');
socket.on('message1', (data) => {
console.log('Recieved from API ::', data)
io.emit('message2', data);
})
});
server.all('*', (req, res) => {
return handle(req, res);
});
const PORT = process.env.PORT || 3000;
httpServer.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
})