a92a5caec2
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
27 lines
772 B
TypeScript
27 lines
772 B
TypeScript
import http from 'http'
|
|
import next from '../next'
|
|
|
|
export default async function start(
|
|
serverOptions: any,
|
|
port?: number,
|
|
hostname?: string
|
|
) {
|
|
const app = next({
|
|
...serverOptions,
|
|
customServer: false,
|
|
})
|
|
const srv = http.createServer(app.getRequestHandler())
|
|
await new Promise<void>((resolve, reject) => {
|
|
// This code catches EADDRINUSE error if the port is already in use
|
|
srv.on('error', reject)
|
|
srv.on('listening', () => resolve())
|
|
srv.listen(port, hostname)
|
|
})
|
|
// It's up to caller to run `app.prepare()`, so it can notify that the server
|
|
// is listening before starting any intensive operations.
|
|
const addr = srv.address()
|
|
return {
|
|
app,
|
|
actualPort: addr && typeof addr === 'object' ? addr.port : port,
|
|
}
|
|
}
|