initialize db before nuxt is ready, fix #131

This commit is contained in:
lesion 2021-12-06 12:11:04 +01:00
parent 40f6978e76
commit 1d80faaa37
No known key found for this signature in database
GPG key ID: 352918250B012177
4 changed files with 16 additions and 20 deletions

View file

@ -83,7 +83,7 @@ export default {
computed: { computed: {
...mapState(['settings']), ...mapState(['settings']),
showSMTPAlert () { showSMTPAlert () {
return !this.setup && !this.settings.admin_email && !this.settings.smtp && !this.settings.smtp.host && !this.settings.smtp.user return !this.setup && (!this.settings.admin_email || !this.settings.smtp || !this.settings.smtp.host || !this.settings.smtp.user)
}, },
instance_locale: { instance_locale: {
get () { return this.settings.instance_locale }, get () { return this.settings.instance_locale },

View file

@ -21,7 +21,6 @@ if (config.firstrun) {
} else { } else {
const { isAuth, isAdmin } = require('./auth') const { isAuth, isAdmin } = require('./auth')
const eventController = require('./controller/event') const eventController = require('./controller/event')
const settingsController = require('./controller/settings') const settingsController = require('./controller/settings')

View file

@ -38,18 +38,18 @@ const db = {
} }
}) })
return await umzug.up() return await umzug.up()
} },
} async initialize () {
if (!config.firstrun) {
if (!config.firstrun) { try {
try { await db.connect()
db.connect().then(e => { log.debug('Running migrations')
log.debug('Running migrations') return db.runMigrations()
db.runMigrations() } catch (e) {
}) log.warn(` ⚠️ Cannot connect to db, check your configuration => ${e}`)
} catch (e) { process.exit(1)
log.warn(` ⚠️ Cannot connect to db, check your configuration => ${e}`) }
process.exit(1) }
} }
} }

View file

@ -1,13 +1,13 @@
export default function () { export default async function () {
async function start (nuxt) {
const log = require('../server/log') const log = require('../server/log')
const config = require('../server/config') const config = require('../server/config')
const settingsController = require('./api/controller/settings') const settingsController = require('./api/controller/settings')
const dayjs = require('dayjs') const dayjs = require('dayjs')
const timezone = require('dayjs/plugin/timezone') const timezone = require('dayjs/plugin/timezone')
const db = require('./api/models/index')
dayjs.extend(timezone) dayjs.extend(timezone)
await db.initialize()
await settingsController.load() await settingsController.load()
dayjs.tz.setDefault(settingsController.settings.instance_timezone) dayjs.tz.setDefault(settingsController.settings.instance_timezone)
@ -26,11 +26,8 @@ export default function () {
await sequelize.close() await sequelize.close()
process.off('SIGTERM', shutdown) process.off('SIGTERM', shutdown)
process.off('SIGINT', shutdown) process.off('SIGINT', shutdown)
nuxt.close()
process.exit() process.exit()
} }
process.on('SIGTERM', shutdown) process.on('SIGTERM', shutdown)
process.on('SIGINT', shutdown) process.on('SIGINT', shutdown)
}
this.nuxt.hook('listen', start)
} }