2019-09-04 16:00:54 +02:00
|
|
|
import Server, { ServerConstructor } from '../next-server/server/next-server'
|
2020-05-04 18:21:58 +02:00
|
|
|
import { NON_STANDARD_NODE_ENV } from '../lib/constants'
|
|
|
|
import * as log from '../build/output/log'
|
2019-09-04 16:00:54 +02:00
|
|
|
|
2020-06-07 01:00:03 +02:00
|
|
|
type NextServerConstructor = ServerConstructor & {
|
2019-09-04 16:00:54 +02:00
|
|
|
/**
|
|
|
|
* Whether to launch Next.js in dev mode - @default false
|
|
|
|
*/
|
|
|
|
dev?: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
// This file is used for when users run `require('next')`
|
|
|
|
function createServer(options: NextServerConstructor): Server {
|
2020-05-04 18:21:58 +02:00
|
|
|
const standardEnv = ['production', 'development', 'test']
|
|
|
|
|
2020-06-03 05:19:29 +02:00
|
|
|
if (options == null) {
|
|
|
|
throw new Error(
|
|
|
|
'The server has not been instantiated properly. https://err.sh/next.js/invalid-server-options'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-04 18:21:58 +02:00
|
|
|
if (
|
|
|
|
!(options as any).isNextDevCommand &&
|
|
|
|
process.env.NODE_ENV &&
|
|
|
|
!standardEnv.includes(process.env.NODE_ENV)
|
|
|
|
) {
|
|
|
|
log.warn(NON_STANDARD_NODE_ENV)
|
|
|
|
}
|
|
|
|
|
2019-09-04 16:00:54 +02:00
|
|
|
if (options.dev) {
|
2020-06-03 05:19:29 +02:00
|
|
|
if (typeof options.dev !== 'boolean') {
|
|
|
|
console.warn(
|
|
|
|
"Warning: 'dev' is not a boolean which could introduce unexpected behavior. https://err.sh/next.js/invalid-server-options"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-06-01 23:00:22 +02:00
|
|
|
const DevServer = require('./next-dev-server').default
|
|
|
|
return new DevServer(options)
|
2019-09-04 16:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return new Server(options)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Support commonjs `require('next')`
|
|
|
|
module.exports = createServer
|
2019-10-31 13:20:05 +01:00
|
|
|
exports = module.exports
|
2019-09-04 16:00:54 +02:00
|
|
|
|
|
|
|
// Support `import next from 'next'`
|
|
|
|
export default createServer
|