-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestServer.ts
39 lines (30 loc) · 945 Bytes
/
testServer.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
35
36
37
38
39
import express, { Request, Response } from 'express'
import next from 'next'
import path from 'path'
const dev = false
const app = next({ dev })
const handle = app.getRequestHandler()
const port = process.env.PORT || 3000
app.prepare().then(() => {
const server = express()
server.use('/_next', express.static(path.join(process.cwd(), '.next')))
server.use('/_next/image', (req: Request, res: Response) => {
handle(req, res)
})
server.all('*', (req: Request, res: Response) => {
return handle(req, res)
})
server.listen(port, (err?: Error) => {
if (err) throw err
// eslint-disable-next-line no-console
console.log(`> Ready on http://localhost:${port}`)
})
})
process.on('uncaughtException', (err: Error) => {
console.error('Uncaught Exception:', err)
process.exit(1)
})
process.on('unhandledRejection', (reason: unknown) => {
console.error('Unhandled Rejection:', reason)
process.exit(1)
})