1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/server/lib/start-server.js
Tim Neutkens fb0b485299
Move out start method from server (#5315)
- This makes sure the Next.js renderer / server doesn't have a dependency on the `http` module.
- Splits out util functions for SSR only
- Removes obsolete methods / methods that weren't being tree-shaken
2018-09-27 21:10:53 +02:00

15 lines
466 B
JavaScript

import http from 'http'
import Server from '../index'
export default async function start (serverOptions, port, hostname) {
const app = new Server(serverOptions)
await app.prepare()
const srv = http.createServer(app.getRequestHandler())
await new Promise((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)
})
}