-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__server__socket-io-trial.js
39 lines (33 loc) · 1.15 KB
/
__server__socket-io-trial.js
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
/* eslint-disable @typescript-eslint/no-var-requires */
const expressApp = require('express')()
const expressServer = require('http').Server(expressApp)
const { parse } = require('url')
const next = require('next')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
app.prepare()
.catch(console.error)
.then(() => {
expressApp.get('*', (req, res) => {
// Be sure to pass `true` as the second argument to `url.parse`.
// This tells it to parse the query portion of the URL.
const parsedUrl = parse(req.url, true)
handle(req, res, { ...parsedUrl, io })
})
expressServer.listen(3000, err => {
if (err) {
console.error(err)
throw err
}
console.log('> Ready on http://localhost:3000')
})
})
// const nextApp = next({ dev })
// const nextHandler = nextApp.getRequestHandler()
// nextApp.prepare().then(() => {
// app.get('*', (req, res) => nextHandler(req, res))
// server.listen(port, err => {
// if (err) throw err
// })
// })