mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
added bit more advanced file existance checking, removed vhosts in favor or routes
This commit is contained in:
parent
ba89f4a342
commit
113a114821
24 changed files with 2720 additions and 2474 deletions
|
@ -40,11 +40,9 @@ import {
|
|||
} from '../../types/basicTypes'
|
||||
import { loadJSON } from '../../utils/actions'
|
||||
import { initWorkerPool } from '../../utils/workerPool'
|
||||
import { paths } from '../../utils/files'
|
||||
|
||||
// files
|
||||
const rootRedirectToFile = 'data/apiRootRedirectTo'
|
||||
|
||||
// other constants
|
||||
// other paths
|
||||
const moduleName = 'API'
|
||||
|
||||
// stuff gotten from server.js
|
||||
|
@ -106,14 +104,14 @@ function GetApp(): ModuleType {
|
|||
let rootRedirectURL = ''
|
||||
|
||||
function reloadRootRedirectURL() {
|
||||
if (utils.FileExists(rootRedirectToFile)) {
|
||||
rootRedirectURL = utils.ReadFile(rootRedirectToFile)
|
||||
if (utils.FileExists(paths.rootRedirectToFile)) {
|
||||
rootRedirectURL = utils.ReadFile(paths.rootRedirectToFile)
|
||||
}
|
||||
}
|
||||
|
||||
const filesToWatch = [
|
||||
{
|
||||
fname: rootRedirectToFile,
|
||||
fname: paths.rootRedirectToFile,
|
||||
logMsg: 'Root redirect URL changed',
|
||||
action: reloadRootRedirectURL,
|
||||
},
|
||||
|
@ -142,7 +140,7 @@ function GetApp(): ModuleType {
|
|||
|
||||
app.get('/', function (req: Request, res: any) {
|
||||
logger.LogReq(req)
|
||||
if (reloadRootRedirectURL) {
|
||||
if (rootRedirectURL) {
|
||||
res.redirect(rootRedirectURL)
|
||||
} else {
|
||||
res.json({ msg: 'hi c:' })
|
||||
|
@ -154,6 +152,9 @@ function GetApp(): ModuleType {
|
|||
const dbsFile = publicDir + 'questionDbs.json'
|
||||
|
||||
// FIXME: is dataFiles only a temp variable? does this cause any problems?
|
||||
if (!utils.FileExists(dbsFile)) {
|
||||
utils.WriteFile('[]', dbsFile)
|
||||
}
|
||||
const dataFiles: Array<DataFile> = utils.ReadJSON(dbsFile)
|
||||
let questionDbs: Array<QuestionDb> = loadJSON(dataFiles, publicDir)
|
||||
initWorkerPool(() => questionDbs)
|
||||
|
@ -176,14 +177,6 @@ function GetApp(): ModuleType {
|
|||
|
||||
// -------------------------------------------------------------------------------------------
|
||||
|
||||
app.get('*', function (_req: Request, res: any) {
|
||||
res.status(404).render('404')
|
||||
})
|
||||
|
||||
app.post('*', function (_req: Request, res: any) {
|
||||
res.status(404).render('404')
|
||||
})
|
||||
|
||||
function DailyAction() {
|
||||
submoduleDatas.forEach((data) => {
|
||||
if (data.dailyAction) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue