mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
added / fixed some types
This commit is contained in:
parent
5f12284bb8
commit
bc5c293539
41 changed files with 4378 additions and 8304 deletions
|
@ -19,16 +19,18 @@
|
|||
------------------------------------------------------------------------- */
|
||||
|
||||
// package requires
|
||||
import express from 'express'
|
||||
import bodyParser from 'body-parser'
|
||||
import express, { RequestHandler } from 'express'
|
||||
import fileUpload from 'express-fileupload'
|
||||
import type { Database } from 'better-sqlite3'
|
||||
import http from 'http'
|
||||
import https from 'https'
|
||||
|
||||
// other requires
|
||||
import logger from '../../utils/logger'
|
||||
import utils from '../../utils/utils'
|
||||
import auth from '../../middlewares/auth.middleware'
|
||||
import { SetupData } from '../../server'
|
||||
import { ModuleType, Request } from '../../types/basicTypes'
|
||||
import { ModuleType, Request, Submodule } from '../../types/basicTypes'
|
||||
|
||||
// files
|
||||
const rootRedirectToFile = 'data/apiRootRedirectTo'
|
||||
|
@ -37,11 +39,11 @@ const rootRedirectToFile = 'data/apiRootRedirectTo'
|
|||
const moduleName = 'API'
|
||||
|
||||
// stuff gotten from server.js
|
||||
let userDB
|
||||
let url
|
||||
let publicdirs = []
|
||||
let httpServer
|
||||
let httpsServer
|
||||
let userDB: Database
|
||||
let url: string
|
||||
let publicdirs: string[] = []
|
||||
let httpServer: http.Server
|
||||
let httpsServer: https.Server
|
||||
|
||||
function GetApp(): ModuleType {
|
||||
const app = express()
|
||||
|
@ -51,7 +53,7 @@ function GetApp(): ModuleType {
|
|||
throw new Error(`No public dir! ( API )`)
|
||||
}
|
||||
|
||||
let domain = url.split('.') // [ "https://api", "frylabs", "net" ]
|
||||
let domain: any = url.split('.') // [ "https://api", "frylabs", "net" ]
|
||||
domain.shift() // [ "frylabs", "net" ]
|
||||
domain = domain.join('.') // "frylabs.net"
|
||||
logger.DebugLog(`Cookie domain: ${domain}`, 'cookie', 1)
|
||||
|
@ -59,15 +61,15 @@ function GetApp(): ModuleType {
|
|||
// -------------------------------------------------------------------------------------------
|
||||
|
||||
app.use(
|
||||
bodyParser.urlencoded({
|
||||
express.urlencoded({
|
||||
limit: '10mb',
|
||||
extended: true,
|
||||
})
|
||||
}) as RequestHandler
|
||||
)
|
||||
app.use(
|
||||
bodyParser.json({
|
||||
express.json({
|
||||
limit: '10mb',
|
||||
})
|
||||
}) as RequestHandler
|
||||
)
|
||||
app.set('view engine', 'ejs')
|
||||
app.set('views', ['./src/modules/api/views', './src/sharedViews'])
|
||||
|
@ -151,11 +153,11 @@ function GetApp(): ModuleType {
|
|||
|
||||
// -------------------------------------------------------------------------------------------
|
||||
|
||||
app.get('*', function (req: Request, res: any) {
|
||||
app.get('*', function (_req: Request, res: any) {
|
||||
res.status(404).render('404')
|
||||
})
|
||||
|
||||
app.post('*', function (req: Request, res: any) {
|
||||
app.post('*', function (_req: Request, res: any) {
|
||||
res.status(404).render('404')
|
||||
})
|
||||
|
||||
|
@ -182,14 +184,14 @@ function GetApp(): ModuleType {
|
|||
function setupSubModules(
|
||||
parentApp: express.Application,
|
||||
moduleSpecificData?: any
|
||||
): any {
|
||||
): Submodule[] {
|
||||
const submoduleDir = './submodules/'
|
||||
const absolutePath = __dirname + '/' + submoduleDir
|
||||
if (!utils.FileExists(absolutePath)) {
|
||||
return
|
||||
return null
|
||||
}
|
||||
const files = utils.ReadDir(absolutePath)
|
||||
const moduleDatas = []
|
||||
const moduleDatas: Submodule[] = []
|
||||
files.forEach((file) => {
|
||||
if (!file.endsWith('.js')) {
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue