mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-02-21 12:49:07 +00:00
feat: verify config files exist on startup
This commit is contained in:
parent
2ddd97541e
commit
f6d85b05ac
50
lolisafe.js
50
lolisafe.js
@ -1,3 +1,15 @@
|
|||||||
|
const logger = require('./logger')
|
||||||
|
|
||||||
|
// Stray errors and exceptions capturers
|
||||||
|
process.on('uncaughtException', error => {
|
||||||
|
logger.error(error, { prefix: 'Uncaught Exception: ' })
|
||||||
|
})
|
||||||
|
|
||||||
|
process.on('unhandledRejection', error => {
|
||||||
|
logger.error(error, { prefix: 'Unhandled Rejection (Promise): ' })
|
||||||
|
})
|
||||||
|
|
||||||
|
// Require libraries
|
||||||
const bodyParser = require('body-parser')
|
const bodyParser = require('body-parser')
|
||||||
const ClamScan = require('clamscan')
|
const ClamScan = require('clamscan')
|
||||||
const contentDisposition = require('content-disposition')
|
const contentDisposition = require('content-disposition')
|
||||||
@ -8,19 +20,27 @@ const path = require('path')
|
|||||||
const RateLimit = require('express-rate-limit')
|
const RateLimit = require('express-rate-limit')
|
||||||
const readline = require('readline')
|
const readline = require('readline')
|
||||||
const serveStatic = require('serve-static')
|
const serveStatic = require('serve-static')
|
||||||
|
const { accessSync, constants } = require('fs')
|
||||||
|
|
||||||
|
// Check required config files
|
||||||
|
const configFiles = ['config.js', 'views/_globals.njk']
|
||||||
|
for (const file of configFiles) {
|
||||||
|
try {
|
||||||
|
accessSync(file, constants.R_OK)
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`Config file '${file}' cannot be found or read.`)
|
||||||
|
logger.error('Please copy the provided sample file and modify it according to your needs.')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Require config files
|
||||||
const config = require('./config')
|
const config = require('./config')
|
||||||
const logger = require('./logger')
|
|
||||||
const versions = require('./src/versions')
|
const versions = require('./src/versions')
|
||||||
const safe = express()
|
|
||||||
|
|
||||||
|
// lolisafe
|
||||||
logger.log('Starting lolisafe\u2026')
|
logger.log('Starting lolisafe\u2026')
|
||||||
|
const safe = express()
|
||||||
process.on('uncaughtException', error => {
|
|
||||||
logger.error(error, { prefix: 'Uncaught Exception: ' })
|
|
||||||
})
|
|
||||||
process.on('unhandledRejection', error => {
|
|
||||||
logger.error(error, { prefix: 'Unhandled Rejection (Promise): ' })
|
|
||||||
})
|
|
||||||
|
|
||||||
const paths = require('./controllers/pathsController')
|
const paths = require('./controllers/pathsController')
|
||||||
const utils = require('./controllers/utilsController')
|
const utils = require('./controllers/utilsController')
|
||||||
@ -37,13 +57,13 @@ if (config.helmet instanceof Object && Object.keys(config.helmet).length) {
|
|||||||
safe.use(helmet(config.helmet))
|
safe.use(helmet(config.helmet))
|
||||||
} else {
|
} else {
|
||||||
// Fallback to old behavior when the whole helmet option was not configurable from the config file
|
// Fallback to old behavior when the whole helmet option was not configurable from the config file
|
||||||
safe.use(helmet({
|
safe.use(helmet({
|
||||||
contentSecurityPolicy: false,
|
contentSecurityPolicy: false,
|
||||||
hsts: false
|
hsts: false
|
||||||
}))
|
}))
|
||||||
|
|
||||||
if (config.hsts instanceof Object && Object.keys(config.hsts).length) {
|
if (config.hsts instanceof Object && Object.keys(config.hsts).length) {
|
||||||
safe.use(helmet.hsts(config.hsts))
|
safe.use(helmet.hsts(config.hsts))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user