mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-02-21 12:49:07 +00:00
clean up lolisafe.js
This commit is contained in:
parent
bd38b78331
commit
8a1fa9f8fb
25
lolisafe.js
25
lolisafe.js
@ -14,6 +14,7 @@ const readline = require('readline')
|
|||||||
const safe = express()
|
const safe = express()
|
||||||
|
|
||||||
// It appears to be best to catch these before doing anything else
|
// It appears to be best to catch these before doing anything else
|
||||||
|
// Probably before require() too, especially require('knex')(db), but nevermind
|
||||||
process.on('uncaughtException', error => {
|
process.on('uncaughtException', error => {
|
||||||
console.error('Uncaught Exception:', error)
|
console.error('Uncaught Exception:', error)
|
||||||
})
|
})
|
||||||
@ -23,6 +24,7 @@ process.on('unhandledRejection', error => {
|
|||||||
|
|
||||||
require('./database/db.js')(db)
|
require('./database/db.js')(db)
|
||||||
|
|
||||||
|
// Check and create missing directories
|
||||||
fs.existsSync('./pages/custom') || fs.mkdirSync('./pages/custom')
|
fs.existsSync('./pages/custom') || fs.mkdirSync('./pages/custom')
|
||||||
fs.existsSync(`./${config.logsFolder}`) || fs.mkdirSync(`./${config.logsFolder}`)
|
fs.existsSync(`./${config.logsFolder}`) || fs.mkdirSync(`./${config.logsFolder}`)
|
||||||
fs.existsSync(`./${config.uploads.folder}`) || fs.mkdirSync(`./${config.uploads.folder}`)
|
fs.existsSync(`./${config.uploads.folder}`) || fs.mkdirSync(`./${config.uploads.folder}`)
|
||||||
@ -37,8 +39,7 @@ if (config.trustProxy) safe.set('trust proxy', 1)
|
|||||||
nunjucks.configure('views', {
|
nunjucks.configure('views', {
|
||||||
autoescape: true,
|
autoescape: true,
|
||||||
express: safe,
|
express: safe,
|
||||||
// watch: true, // will this be fine in production?
|
noCache: process.env.NODE_ENV === 'development'
|
||||||
noCache: process.env.DEV === '1'
|
|
||||||
})
|
})
|
||||||
safe.set('view engine', 'njk')
|
safe.set('view engine', 'njk')
|
||||||
safe.enable('view cache')
|
safe.enable('view cache')
|
||||||
@ -118,18 +119,20 @@ const start = async () => {
|
|||||||
safe.set('git-hash', gitHash)
|
safe.set('git-hash', gitHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.uploads.scan && config.uploads.scan.enabled) {
|
const scan = config.uploads.scan
|
||||||
|
if (scan && scan.enabled) {
|
||||||
const created = await new Promise(async (resolve, reject) => {
|
const created = await new Promise(async (resolve, reject) => {
|
||||||
if (!config.uploads.scan.ip || !config.uploads.scan.port)
|
if (!scan.ip || !scan.port)
|
||||||
return reject(new Error('clamd IP or port is missing'))
|
return reject(new Error('clamd IP or port is missing'))
|
||||||
|
|
||||||
const ping = await clamd.ping(config.uploads.scan.ip, config.uploads.scan.port).catch(reject)
|
const ping = await clamd.ping(scan.ip, scan.port).catch(reject)
|
||||||
if (!ping)
|
if (!ping)
|
||||||
return reject(new Error('Could not ping clamd'))
|
return reject(new Error('Could not ping clamd'))
|
||||||
|
|
||||||
const version = await clamd.version(config.uploads.scan.ip, config.uploads.scan.port).catch(reject)
|
const version = await clamd.version(scan.ip, scan.port).catch(reject)
|
||||||
console.log(`${config.uploads.scan.ip}:${config.uploads.scan.port} ${version}`)
|
console.log(`${scan.ip}:${scan.port} ${version}`)
|
||||||
const scanner = clamd.createScanner(config.uploads.scan.ip, config.uploads.scan.port)
|
|
||||||
|
const scanner = clamd.createScanner(scan.ip, scan.port)
|
||||||
safe.set('clam-scanner', scanner)
|
safe.set('clam-scanner', scanner)
|
||||||
return resolve(true)
|
return resolve(true)
|
||||||
}).catch(error => console.error(error.toString()))
|
}).catch(error => console.error(error.toString()))
|
||||||
@ -155,8 +158,8 @@ const start = async () => {
|
|||||||
|
|
||||||
safe.listen(config.port, () => {
|
safe.listen(config.port, () => {
|
||||||
console.log(`lolisafe started on port ${config.port}`)
|
console.log(`lolisafe started on port ${config.port}`)
|
||||||
// DEV=1 yarn start
|
// NODE_ENV=development yarn start
|
||||||
if (process.env.DEV === '1') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
// 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,
|
||||||
@ -173,7 +176,7 @@ const start = async () => {
|
|||||||
}).on('SIGINT', () => {
|
}).on('SIGINT', () => {
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
})
|
})
|
||||||
console.warn('development mode enabled (disabled nunjucks caching & enabled readline interface)')
|
console.log('Development mode enabled (disabled nunjucks caching & enabled readline interface)')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user