mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added support for submodules
This commit is contained in:
parent
7e70aa6c8e
commit
2a0926aa7e
3 changed files with 44 additions and 4 deletions
|
@ -28,7 +28,7 @@ module.exports = {
|
||||||
'@typescript-eslint/ban-types': 'off',
|
'@typescript-eslint/ban-types': 'off',
|
||||||
'id-length': [
|
'id-length': [
|
||||||
'warn',
|
'warn',
|
||||||
{ exceptions: ['i', 'j', 't', 'Q', 'A', 'C', 'q', 'a', 'b', 'x'] },
|
{ exceptions: ['i', 'j', 't', 'Q', 'A', 'C', 'q', 'a', 'b', 'x', 'e'] },
|
||||||
],
|
],
|
||||||
'object-shorthand': ['warn', 'never'],
|
'object-shorthand': ['warn', 'never'],
|
||||||
'prefer-const': 'warn',
|
'prefer-const': 'warn',
|
||||||
|
|
|
@ -46,7 +46,7 @@ import {
|
||||||
dataToString,
|
dataToString,
|
||||||
getSubjNameWithoutYear,
|
getSubjNameWithoutYear,
|
||||||
createQuestion,
|
createQuestion,
|
||||||
compareQuestionObj,
|
// compareQuestionObj,
|
||||||
} from '../../utils/classes'
|
} from '../../utils/classes'
|
||||||
import {
|
import {
|
||||||
initWorkerPool,
|
initWorkerPool,
|
||||||
|
@ -85,6 +85,7 @@ const uloadFiles = 'data/f'
|
||||||
|
|
||||||
// other constants
|
// other constants
|
||||||
const line = '====================================================' // lol
|
const line = '====================================================' // lol
|
||||||
|
const moduleName = 'API'
|
||||||
const addPWPerDay = 3 // every x day a user can give a pw
|
const addPWPerDay = 3 // every x day a user can give a pw
|
||||||
const maxPWCount = 6 // maximum pw give opportunities a user can have at once
|
const maxPWCount = 6 // maximum pw give opportunities a user can have at once
|
||||||
const addPWCount = 1 // how many pw gen opportunities to add each time
|
const addPWCount = 1 // how many pw gen opportunities to add each time
|
||||||
|
@ -93,7 +94,7 @@ const minimumAlowwedSessions = 2 // how many sessions are allowed for a user
|
||||||
|
|
||||||
// stuff gotten from server.js
|
// stuff gotten from server.js
|
||||||
let userDB
|
let userDB
|
||||||
let url // eslint-disable-line
|
let url
|
||||||
let publicdirs = []
|
let publicdirs = []
|
||||||
|
|
||||||
function GetApp(): ModuleType {
|
function GetApp(): ModuleType {
|
||||||
|
@ -1951,6 +1952,8 @@ function GetApp(): ModuleType {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setupSubModules(app)
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
app.get('*', function(req: Request, res: any) {
|
app.get('*', function(req: Request, res: any) {
|
||||||
|
@ -2050,8 +2053,37 @@ function GetApp(): ModuleType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setupSubModules(parentApp) {
|
||||||
|
const submoduleDir = './submodules/'
|
||||||
|
const absolutePath = __dirname + '/' + submoduleDir
|
||||||
|
if (!utils.FileExists(absolutePath)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const files = utils.ReadDir(absolutePath)
|
||||||
|
files.forEach((file) => {
|
||||||
|
if (!file.endsWith('.js')) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const submodulePath = submoduleDir + file
|
||||||
|
|
||||||
|
try {
|
||||||
|
const mod = require(submodulePath).default // eslint-disable-line
|
||||||
|
mod.setup({
|
||||||
|
app: parentApp,
|
||||||
|
userDB: userDB,
|
||||||
|
url: url,
|
||||||
|
publicdirs: publicdirs,
|
||||||
|
})
|
||||||
|
logger.Log(`Submodule '${file}' loaded for '${moduleName}'`)
|
||||||
|
} catch (e) {
|
||||||
|
logger.Log(`Error loading submodule from ${submodulePath}`)
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'API',
|
name: moduleName,
|
||||||
getApp: GetApp,
|
getApp: GetApp,
|
||||||
setup: (data: SetupData): void => {
|
setup: (data: SetupData): void => {
|
||||||
userDB = data.userDB
|
userDB = data.userDB
|
||||||
|
|
|
@ -73,3 +73,11 @@ export interface Request extends express.Request {
|
||||||
session: any
|
session: any
|
||||||
busboy: any
|
busboy: any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SubmoduleData {
|
||||||
|
app: express.Application
|
||||||
|
url: string
|
||||||
|
publicdirs: Array<string>
|
||||||
|
userDB?: any
|
||||||
|
nextdir?: string
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue