-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathserver.ts
More file actions
26 lines (21 loc) · 749 Bytes
/
server.ts
File metadata and controls
26 lines (21 loc) · 749 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
import http, { type IncomingMessage, type ServerResponse } from 'http'
import next from 'next'
import { initializeSocket } from './socket-server'
const dev = process.env.NODE_ENV !== 'production'
const hostname = process.env.HOSTNAME || '0.0.0.0'
const port = Number(process.env.PORT) || 3000
const app = next({ dev, hostname, port })
const handle = app.getRequestHandler()
app
.prepare()
.then(() => {
const httpServer = http.createServer((req: IncomingMessage, res: ServerResponse) => handle(req, res))
initializeSocket(httpServer)
httpServer.listen(port, hostname, () => {
console.log(`> Ready on http://${hostname}:${port}`)
})
})
.catch((error: unknown) => {
console.error(error)
process.exit(1)
})