Exit cleanup functions, authentication polish, db polish

This commit is contained in:
MrFry 2020-04-07 14:09:34 +02:00
parent fb8e12f8d2
commit c764c4f402
10 changed files with 314 additions and 229 deletions

View file

@ -52,12 +52,40 @@ try {
console.log(e)
}
// Setting up exits
// process.on('exit', () => exit('exit'))
// process.on('exit', () => exit('exit'))
process.on('SIGINT', () => exit('SIGINT'))
process.on('SIGINT', () => exit('SIGINT'))
process.on('SIGTERM', () => exit('SIGTERM'))
process.on('SIGTERM', () => exit('SIGTERM'))
function exit (reason) {
logger.Log(`Exiting, reason: ${reason}`)
Object.keys(modules).forEach((k, i) => {
const x = modules[k]
if (x.cleanup) {
try {
x.cleanup()
} catch (e) {
logger.Log(`Error in ${k} cleanup! Details in STDERR`, logger.GetColor('redbg'))
console.err(e)
}
}
})
process.exit()
}
const app = express()
app.use(cors())
app.use(reqlogger([
'stable.user.js', // TODO
'dataeditor'
]))
app.use(reqlogger({
loggableKeywords: [
'stable.user.js'
],
loggableModules: [
'dataeditor'
]
}))
Object.keys(modules).forEach(function (k, i) {
let x = modules[k]
@ -65,11 +93,12 @@ Object.keys(modules).forEach(function (k, i) {
let mod = require(x.path)
if (mod.setup) {
mod.setup({
url: 'http://' + x.urls[0] // TODO http https or neither
url: 'https://' + x.urls[0]
})
}
x.app = mod.app
x.dailyAction = mod.dailyAction
x.cleanup = mod.cleanup
x.urls.forEach((url) => {
app.use(vhost(url, x.app))
})
@ -127,7 +156,12 @@ function setLogTimer () {
Object.keys(modules).forEach((k, i) => {
const x = modules[k]
if (x.dailyAction) {
x.dailyAction()
try {
x.dailyAction()
} catch (e) {
logger.Log(`Error in ${k} daily action! Details in STDERR`, logger.GetColor('redbg'))
console.err(e)
}
}
})