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: {
...mapState(['settings']),
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: {
get () { return this.settings.instance_locale },

View file

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

View file

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

View file

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