2020-09-27 15:10:11 +03:00
|
|
|
require('./lib/check-node-version')
|
|
|
|
require('./lib/handle-exceptions')
|
|
|
|
require('./lib/feature-flags')
|
|
|
|
|
|
|
|
const express = require('express')
|
2020-09-29 18:51:48 +03:00
|
|
|
const portUsed = require('port-used')
|
2020-09-27 15:10:11 +03:00
|
|
|
const warmServer = require('./lib/warm-server')
|
|
|
|
const port = Number(process.env.PORT) || 4000
|
|
|
|
const app = express()
|
|
|
|
|
|
|
|
require('./middleware')(app)
|
|
|
|
|
|
|
|
// prevent the app from starting up durings tests
|
|
|
|
/* istanbul ignore next */
|
|
|
|
if (!module.parent) {
|
|
|
|
// check that the development server is not already running
|
2020-09-29 18:51:48 +03:00
|
|
|
portUsed.check(port).then(async status => {
|
|
|
|
if (status === false) {
|
2020-09-27 15:10:11 +03:00
|
|
|
// If in production, warm the server at the start
|
2020-10-21 17:26:50 +03:00
|
|
|
if (process.env.NODE_ENV === 'production') warmServer()
|
2020-09-27 15:10:11 +03:00
|
|
|
|
|
|
|
// workaround for https://github.com/expressjs/express/issues/1101
|
|
|
|
const server = require('http').createServer(app)
|
|
|
|
server.listen(port, () => console.log(`app running on http://localhost:${port}`))
|
|
|
|
.on('error', () => server.close())
|
|
|
|
} else {
|
|
|
|
console.log(`\n\n\nPort ${port} is not available. You may already have a server running.`)
|
|
|
|
console.log('Try running `killall node` to shut down all your running node processes.\n\n\n')
|
|
|
|
console.log('\x07') // system 'beep' sound
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = app
|