could listen to unix socket, better conf

This commit is contained in:
lesion
2019-06-10 00:40:37 +02:00
parent d1a56e5135
commit b01f4ef04d
15 changed files with 107 additions and 76 deletions

View File

@@ -6,17 +6,18 @@ const morgan = require('morgan')
const { Nuxt, Builder } = require('nuxt')
const firstRun = require('./firstrun')
// Import and Set Nuxt.js options
const config = require('../nuxt.config.js')
const nuxt_config = require('../nuxt.config.js')
const config = require('./config')
const app = express()
async function start() {
// Init Nuxt.js
const nuxt = new Nuxt(config)
const nuxt = new Nuxt(nuxt_config)
const { host, port } = nuxt.options.server
// const { host, port } = nuxt.options.server
// Build only in dev mode
if (config.dev) {
if (nuxt_config.dev) {
const builder = new Builder(nuxt)
await builder.build()
} else {
@@ -29,10 +30,26 @@ async function start() {
app.use(nuxt.render)
// Listen the server
app.listen(port, host)
consola.ready({
message: `Server listening on http://${host}:${port}`,
badge: true
const server = app.listen(config.server)
// close connections/port/unix socket
function shutdown() {
consola.info(`Closing connections..`)
server.close()
}
process.on('SIGTERM', shutdown)
process.on('SIGINT', shutdown)
server.on('error', e => {
consola.error(e)
})
server.on('listening', () => {
const address = server.address()
consola.ready({
message: `Server listening on ${(typeof address) === 'object' ? `${address.address}:${address.port}` : address}`,
badge: true
})
})
}