mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Exit cleanup functions, authentication polish, db polish
This commit is contained in:
parent
fb8e12f8d2
commit
c764c4f402
10 changed files with 314 additions and 229 deletions
46
server.js
46
server.js
|
@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue