style: dev mode messages

This commit is contained in:
Bobby 2022-04-16 21:37:17 +07:00
parent 1c0fd26496
commit d878d161c0
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09

View File

@ -51,6 +51,7 @@ const nojs = require('./routes/nojs')
const player = require('./routes/player') const player = require('./routes/player')
const db = require('knex')(config.database) const db = require('knex')(config.database)
const isDevMode = process.env.NODE_ENV === 'development'
// Helmet security headers // Helmet security headers
if (config.helmet instanceof Object && Object.keys(config.helmet).length) { if (config.helmet instanceof Object && Object.keys(config.helmet).length) {
@ -75,8 +76,8 @@ if (config.trustProxy) {
nunjucks.configure('views', { nunjucks.configure('views', {
autoescape: true, autoescape: true,
express: safe, express: safe,
watch: process.env.NODE_ENV === 'development' watch: isDevMode
// noCache: process.env.NODE_ENV === 'development' // noCache: isDevMode
}) })
safe.set('view engine', 'njk') safe.set('view engine', 'njk')
safe.enable('view cache') safe.enable('view cache')
@ -388,7 +389,7 @@ safe.use('/api', api)
} }
// NODE_ENV=development yarn start // NODE_ENV=development yarn start
if (process.env.NODE_ENV === 'development') { if (isDevMode) {
// Add readline interface to allow evaluating arbitrary JavaScript from console // Add readline interface to allow evaluating arbitrary JavaScript from console
readline.createInterface({ readline.createInterface({
input: process.stdin, input: process.stdin,
@ -406,7 +407,10 @@ safe.use('/api', api)
}).on('SIGINT', () => { }).on('SIGINT', () => {
process.exit(0) process.exit(0)
}) })
logger.log('DEVELOPMENT MODE: Disabled Nunjucks caching & enabled readline interface') logger.log('!!! DEVELOPMENT MODE !!!')
logger.log('- Nunjucks will auto rebuild (not live reload)')
logger.log('- Rate limits disabled')
logger.log('- Readline interface enabled')
} }
} catch (error) { } catch (error) {
logger.error(error) logger.error(error)