mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Prettied some stuff, and moved submodules around again
This commit is contained in:
parent
d8ef7cdcb0
commit
3f081d8dff
6 changed files with 106 additions and 182 deletions
|
@ -53,7 +53,7 @@ try {
|
|||
const extraModules = JSON.parse(utils.ReadFile(extraModulesFile))
|
||||
modules = {
|
||||
...extraModules,
|
||||
...modules
|
||||
...modules,
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
@ -66,7 +66,7 @@ try {
|
|||
process.on('SIGINT', () => exit('SIGINT'))
|
||||
process.on('SIGTERM', () => exit('SIGTERM'))
|
||||
|
||||
function exit (reason) {
|
||||
function exit(reason) {
|
||||
console.log()
|
||||
logger.Log(`Exiting, reason: ${reason}`)
|
||||
Object.keys(modules).forEach((k, i) => {
|
||||
|
@ -75,7 +75,10 @@ function exit (reason) {
|
|||
try {
|
||||
x.cleanup()
|
||||
} catch (e) {
|
||||
logger.Log(`Error in ${k} cleanup! Details in STDERR`, logger.GetColor('redbg'))
|
||||
logger.Log(
|
||||
`Error in ${k} cleanup! Details in STDERR`,
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
@ -90,11 +93,17 @@ function exit (reason) {
|
|||
const app = express()
|
||||
|
||||
if (!process.env.NS_DEVEL) {
|
||||
app.use(function (req, res, next) {
|
||||
app.use(function(req, res, next) {
|
||||
if (req.secure) {
|
||||
next()
|
||||
} else {
|
||||
logger.DebugLog(`HTTPS ${req.method} redirect to: ${'https://' + req.headers.host + req.url}`, 'https', 1)
|
||||
logger.DebugLog(
|
||||
`HTTPS ${req.method} redirect to: ${'https://' +
|
||||
req.headers.host +
|
||||
req.url}`,
|
||||
'https',
|
||||
1
|
||||
)
|
||||
if (req.method === 'POST') {
|
||||
res.redirect(307, 'https://' + req.headers.host + req.url)
|
||||
} else {
|
||||
|
@ -104,23 +113,23 @@ if (!process.env.NS_DEVEL) {
|
|||
})
|
||||
}
|
||||
// https://github.com/expressjs/cors#configuration-options
|
||||
app.use(cors({
|
||||
credentials: true,
|
||||
origin: true
|
||||
// origin: [ /\.frylabs\.net$/ ]
|
||||
}))
|
||||
app.use(
|
||||
cors({
|
||||
credentials: true,
|
||||
origin: true,
|
||||
// origin: [ /\.frylabs\.net$/ ]
|
||||
})
|
||||
)
|
||||
const cookieSecret = uuidv4()
|
||||
app.use(cookieParser(cookieSecret))
|
||||
app.use(reqlogger({
|
||||
loggableKeywords: [
|
||||
'stable.user.js'
|
||||
],
|
||||
loggableModules: [
|
||||
'dataeditor'
|
||||
]
|
||||
}))
|
||||
app.use(
|
||||
reqlogger({
|
||||
loggableKeywords: ['stable.user.js'],
|
||||
loggableModules: ['dataeditor'],
|
||||
})
|
||||
)
|
||||
|
||||
Object.keys(modules).forEach(function (k, i) {
|
||||
Object.keys(modules).forEach(function(k, i) {
|
||||
let x = modules[k]
|
||||
try {
|
||||
let mod = require(x.path)
|
||||
|
@ -135,7 +144,7 @@ Object.keys(modules).forEach(function (k, i) {
|
|||
url: 'https://' + x.urls[0],
|
||||
userDB: userDB,
|
||||
publicdirs: x.publicdirs,
|
||||
nextdir: x.nextdir
|
||||
nextdir: x.nextdir,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -161,8 +170,12 @@ const fullchainFile = '/etc/letsencrypt/live/frylabs.net/fullchain.pem'
|
|||
const chainFile = '/etc/letsencrypt/live/frylabs.net/chain.pem'
|
||||
|
||||
var certsLoaded = false
|
||||
if (startHTTPS && utils.FileExists(privkeyFile) && utils.FileExists(fullchainFile) && utils.FileExists(
|
||||
chainFile)) {
|
||||
if (
|
||||
startHTTPS &&
|
||||
utils.FileExists(privkeyFile) &&
|
||||
utils.FileExists(fullchainFile) &&
|
||||
utils.FileExists(chainFile)
|
||||
) {
|
||||
try {
|
||||
const key = utils.ReadFile(privkeyFile)
|
||||
const cert = utils.ReadFile(fullchainFile)
|
||||
|
@ -170,7 +183,7 @@ if (startHTTPS && utils.FileExists(privkeyFile) && utils.FileExists(fullchainFil
|
|||
var certs = {
|
||||
key: key,
|
||||
cert: cert,
|
||||
ca: ca
|
||||
ca: ca,
|
||||
}
|
||||
certsLoaded = true
|
||||
} catch (e) {
|
||||
|
@ -180,7 +193,7 @@ if (startHTTPS && utils.FileExists(privkeyFile) && utils.FileExists(fullchainFil
|
|||
}
|
||||
|
||||
setLogTimer()
|
||||
function setLogTimer () {
|
||||
function setLogTimer() {
|
||||
const now = new Date()
|
||||
const night = new Date(
|
||||
now.getFullYear(),
|
||||
|
@ -196,17 +209,20 @@ function setLogTimer () {
|
|||
logger.DebugLog(`Seconds To Midnight: ${msToMidnight / 1000}`, 'daily', 1)
|
||||
|
||||
if (msToMidnight < 0) {
|
||||
logger.Log(`Error setting up Log Timer, msToMidnight is negative! (${msToMidnight})`, logger.GetColor('redbg'))
|
||||
logger.Log(
|
||||
`Error setting up Log Timer, msToMidnight is negative! (${msToMidnight})`,
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
setTimeout(function () {
|
||||
setTimeout(function() {
|
||||
LogTimerAction()
|
||||
setLogTimer()
|
||||
}, msToMidnight)
|
||||
}
|
||||
|
||||
function LogTimerAction () {
|
||||
function LogTimerAction() {
|
||||
logger.DebugLog(`Running Log Timer Action`, 'daily', 1)
|
||||
Object.keys(modules).forEach((k, i) => {
|
||||
const x = modules[k]
|
||||
|
@ -216,13 +232,17 @@ function LogTimerAction () {
|
|||
logger.Log(`Running daily action of ${k}`)
|
||||
x.dailyAction()
|
||||
} catch (e) {
|
||||
logger.Log(`Error in ${k} daily action! Details in STDERR`, logger.GetColor('redbg'))
|
||||
logger.Log(
|
||||
`Error in ${k} daily action! Details in STDERR`,
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
console.err(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const line = '==================================================================================================================================================='
|
||||
const line =
|
||||
'==================================================================================================================================================='
|
||||
logger.Log(line)
|
||||
utils.AppendToFile(line, locLogFile)
|
||||
utils.AppendToFile(line, allLogFile)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue