mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Modules now return a function which creates app-s, qmining module auth handle
This commit is contained in:
parent
b5f9ede2cf
commit
a03f56028a
12 changed files with 1046 additions and 990 deletions
38
server.js
38
server.js
|
@ -20,7 +20,7 @@
|
|||
console.clear()
|
||||
|
||||
const startHTTPS = true
|
||||
const port = 8080
|
||||
const port = 80
|
||||
const httpsport = 5001
|
||||
|
||||
const express = require('express')
|
||||
|
@ -30,10 +30,19 @@ const utils = require('./utils/utils.js')
|
|||
const http = require('http')
|
||||
const https = require('https')
|
||||
const cors = require('cors')
|
||||
const cookieParser = require('cookie-parser')
|
||||
const uuidv4 = require('uuid/v4') // TODO: deprecated, but imports are not supported
|
||||
|
||||
const dbtools = require('./utils/dbtools.js')
|
||||
const reqlogger = require('./middlewares/reqlogger.middleware.js')
|
||||
const extraModulesFile = './extraModules.json'
|
||||
const modulesFile = './modules.json'
|
||||
const usersDBPath = 'data/dbs/users.db'
|
||||
|
||||
if (!utils.FileExists(usersDBPath)) {
|
||||
throw new Error('No user DB exists yet! please run utils/dbSetup.js first!')
|
||||
}
|
||||
const userDB = dbtools.GetDB(usersDBPath)
|
||||
|
||||
let modules = JSON.parse(utils.ReadFile(modulesFile))
|
||||
|
||||
|
@ -70,15 +79,25 @@ function exit (reason) {
|
|||
x.cleanup()
|
||||
} catch (e) {
|
||||
logger.Log(`Error in ${k} cleanup! Details in STDERR`, logger.GetColor('redbg'))
|
||||
console.err(e)
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
logger.Log('Closing Auth DB')
|
||||
userDB.close()
|
||||
|
||||
process.exit()
|
||||
}
|
||||
|
||||
const app = express()
|
||||
app.use(cors())
|
||||
app.use(cors({
|
||||
credentials: true,
|
||||
origin: true
|
||||
// origin: [ /\.frylabs\.net$/ ]
|
||||
}))
|
||||
const cookieSecret = uuidv4()
|
||||
app.use(cookieParser(cookieSecret))
|
||||
app.use(reqlogger({
|
||||
loggableKeywords: [
|
||||
'stable.user.js'
|
||||
|
@ -92,14 +111,19 @@ Object.keys(modules).forEach(function (k, i) {
|
|||
let x = modules[k]
|
||||
try {
|
||||
let mod = require(x.path)
|
||||
logger.Log(`Loading ${mod.name} module`, logger.GetColor('yellow'))
|
||||
if (mod.setup) {
|
||||
mod.setup({
|
||||
url: 'https://' + x.urls[0]
|
||||
url: 'https://' + x.urls[0],
|
||||
userDB: userDB
|
||||
})
|
||||
}
|
||||
x.app = mod.app
|
||||
x.dailyAction = mod.dailyAction
|
||||
x.cleanup = mod.cleanup
|
||||
|
||||
const modApp = mod.getApp()
|
||||
x.app = modApp.app
|
||||
x.dailyAction = modApp.DailyAction
|
||||
x.cleanup = modApp.cleanup
|
||||
|
||||
x.urls.forEach((url) => {
|
||||
app.use(vhost(url, x.app))
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue