From d430417af2a7eb245b4ec21e1f27290a61bc5762 Mon Sep 17 00:00:00 2001 From: lesion Date: Thu, 10 Mar 2022 12:37:05 +0100 Subject: [PATCH] minor with logging and cleanup bootstrap --- server/api/auth.js | 6 +++--- server/api/oauth.js | 2 +- server/initialize.server.js | 24 +++++++++--------------- server/log.js | 2 +- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/server/api/auth.js b/server/api/auth.js index e57792b3..9cb56a23 100644 --- a/server/api/auth.js +++ b/server/api/auth.js @@ -25,15 +25,15 @@ const Auth = { if (res.locals.user) { next() } else { - res.sendStatus(404) + res.sendStatus(403) } }, isAdmin (req, res, next) { - if (res.locals.user.is_admin) { + if (res.locals.users && res.locals.user.is_admin) { next() } else { - res.status(404) + res.sendStatus(403) } }, diff --git a/server/api/oauth.js b/server/api/oauth.js index 96690131..0bf5306a 100644 --- a/server/api/oauth.js +++ b/server/api/oauth.js @@ -34,7 +34,7 @@ oauth.use((req, res) => res.sendStatus(404)) oauth.use((err, req, res, next) => { const error_msg = err.toString() - log.error('[OAUTH USE] ' + error_msg) + log.warn('[OAUTH USE] ' + error_msg) res.status(500).send(error_msg) }) diff --git a/server/initialize.server.js b/server/initialize.server.js index f835d6a9..1fe1acb3 100644 --- a/server/initialize.server.js +++ b/server/initialize.server.js @@ -1,14 +1,13 @@ -const config = require('../server/config') -const settingsController = require('./api/controller/settings') -const log = require('../server/log') -const db = require('./api/models/index') -const dayjs = require('dayjs') -const timezone = require('dayjs/plugin/timezone') -// export default async function () { -module.exports = async function () { +module.exports = function () { + const config = require('../server/config') + config.load() + const log = require('../server/log') + const settingsController = require('./api/controller/settings') + const db = require('./api/models/index') + const dayjs = require('dayjs') + const timezone = require('dayjs/plugin/timezone') async function start (nuxt) { - config.load() if (config.status == 'READY') { await db.initialize() @@ -55,10 +54,5 @@ module.exports = async function () { process.on('SIGINT', shutdown) } - if (this.nuxt) { - this.nuxt.hook('build:done', process.exit) - return start(this.nuxt) - } else { - return start() - } + return start(this.nuxt) } diff --git a/server/log.js b/server/log.js index 16bf014f..4ab28960 100644 --- a/server/log.js +++ b/server/log.js @@ -15,7 +15,7 @@ const logger = createLogger({ transports: process.env.NODE_ENV !== 'production' ? [new transports.Console( { - level: 'debug', + level: config.log_level || 'debug', format: format.combine(format.splat(), format.timestamp(), format.colorize(), gancioFormat) } )]