gancio-upstream/server/index.js

45 lines
1 KiB
JavaScript
Raw Normal View History

2019-06-06 23:54:32 +02:00
const { Nuxt, Builder } = require('nuxt')
2019-07-03 16:58:24 +02:00
2019-04-03 00:25:12 +02:00
// Import and Set Nuxt.js options
const nuxtConfig = require('../nuxt.config.js')
const config = require('config')
2019-10-02 20:57:33 +02:00
const consola = require('consola')
const { TaskManager } = require('./taskManager')
2019-04-03 00:25:12 +02:00
2019-09-11 19:12:24 +02:00
async function main () {
nuxtConfig.server = config.server
2019-08-09 13:21:32 +02:00
2019-04-03 00:25:12 +02:00
// Init Nuxt.js
const nuxt = new Nuxt(nuxtConfig)
2019-04-03 00:25:12 +02:00
// Build only in dev mode
if (nuxtConfig.dev) {
2019-04-03 00:25:12 +02:00
const builder = new Builder(nuxt)
await builder.build()
} else {
await nuxt.ready()
}
2020-02-16 21:04:46 +01:00
try {
await nuxt.listen()
} catch (e) {
consola.error(e.toString())
return
}
2019-10-28 17:33:20 +01:00
consola.info('Listen on %s:%d , visit me here => %s', config.server.host, config.server.port, config.baseurl)
TaskManager.start()
2019-04-03 00:25:12 +02:00
// close connections/port/unix socket
2019-09-11 19:12:24 +02:00
function shutdown () {
TaskManager.stop()
2019-08-25 14:34:26 +02:00
nuxt.close(async () => {
2020-06-27 02:10:10 +02:00
const sequelize = require('./api/models')
await sequelize.close()
2019-07-08 00:49:03 +02:00
process.exit()
})
}
process.on('SIGTERM', shutdown)
process.on('SIGINT', shutdown)
2019-04-03 00:25:12 +02:00
}
2019-06-06 23:54:32 +02:00
2019-08-09 13:21:32 +02:00
main()