gancio/server/index.js

52 lines
1.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')
2021-03-05 14:17:10 +01:00
const log = require('./log')
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
if (!nuxtConfig.dev) {
nuxtConfig.buildModules = []
}
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()
}
2021-06-21 00:44:43 +02:00
2020-02-16 21:04:46 +01:00
try {
await nuxt.listen()
} catch (e) {
2021-06-21 00:44:43 +02:00
log.error({ message: e.message })
2020-02-16 21:04:46 +01:00
return
}
2021-02-09 12:17:10 +01:00
const { TaskManager } = require('./taskManager')
TaskManager.start()
2021-02-09 12:17:10 +01:00
const msg = `Listen on ${config.server.host}:${config.server.port} , visit me here => ${config.baseurl}`
2021-03-05 14:17:10 +01:00
log.info(msg)
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 () => {
2021-03-05 14:17:10 +01:00
log.info('Closing DB')
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()