mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
removed some domain dependencies
This commit is contained in:
parent
f8a7c6a4e5
commit
bc45b11551
13 changed files with 17 additions and 31 deletions
|
@ -24,7 +24,6 @@ import type { Database } from 'better-sqlite3'
|
||||||
|
|
||||||
import logger from '../utils/logger'
|
import logger from '../utils/logger'
|
||||||
import dbtools from '../utils/dbtools'
|
import dbtools from '../utils/dbtools'
|
||||||
import constants from '../constants'
|
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
userDB: Database
|
userDB: Database
|
||||||
|
@ -51,9 +50,7 @@ function renderLogin(req: Request, res: Response) {
|
||||||
msg: 'You are not logged in',
|
msg: 'You are not logged in',
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
res.render('login', {
|
res.render('login')
|
||||||
domain: constants.domain,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -214,7 +214,7 @@ function setupSubModules(
|
||||||
const loadedModData = mod.setup({
|
const loadedModData = mod.setup({
|
||||||
app: parentApp,
|
app: parentApp,
|
||||||
userDB: userDB,
|
userDB: userDB,
|
||||||
url: url,
|
url: url, // only used by userManagement.ts
|
||||||
publicdirs: publicdirs,
|
publicdirs: publicdirs,
|
||||||
moduleSpecificData: moduleSpecificData,
|
moduleSpecificData: moduleSpecificData,
|
||||||
httpServer: httpServer,
|
httpServer: httpServer,
|
||||||
|
|
|
@ -26,7 +26,7 @@ import { Request, SubmoduleData } from '../../../types/basicTypes'
|
||||||
const uloadFiles = 'data/f'
|
const uloadFiles = 'data/f'
|
||||||
|
|
||||||
function setup(data: SubmoduleData): void {
|
function setup(data: SubmoduleData): void {
|
||||||
const { app /* userDB, url, publicdirs, moduleSpecificData */ } = data
|
const { app } = data
|
||||||
|
|
||||||
app.route('/fosuploader').post(function (req: Request, res: Response) {
|
app.route('/fosuploader').post(function (req: Request, res: Response) {
|
||||||
utils.uploadFile(req, uloadFiles).then(({ fileName }) => {
|
utils.uploadFile(req, uloadFiles).then(({ fileName }) => {
|
||||||
|
|
|
@ -184,8 +184,7 @@ function getPostData(
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup(data: SubmoduleData): void {
|
function setup(data: SubmoduleData): void {
|
||||||
const { app, /* userDB, url, */ publicdirs /*, moduleSpecificData */ } =
|
const { app, publicdirs } = data
|
||||||
data
|
|
||||||
|
|
||||||
const publicDir = publicdirs[0]
|
const publicDir = publicdirs[0]
|
||||||
|
|
||||||
|
|
|
@ -450,7 +450,7 @@ function setup(data: SubmoduleData): Submodule {
|
||||||
const {
|
const {
|
||||||
app,
|
app,
|
||||||
userDB,
|
userDB,
|
||||||
/* url */ publicdirs,
|
publicdirs,
|
||||||
moduleSpecificData: { getQuestionDbs, setQuestionDbs, dbsFile },
|
moduleSpecificData: { getQuestionDbs, setQuestionDbs, dbsFile },
|
||||||
} = data
|
} = data
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ interface QuickVote {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup(data: SubmoduleData): void {
|
function setup(data: SubmoduleData): void {
|
||||||
const { app /* userDB, url, publicdirs, moduleSpecificData */ } = data
|
const { app } = data
|
||||||
|
|
||||||
app.get('/quickvote', (req: Request, res: Response) => {
|
app.get('/quickvote', (req: Request, res: Response) => {
|
||||||
const key = req.query.key.toString()
|
const key = req.query.key.toString()
|
||||||
|
|
|
@ -58,7 +58,7 @@ function mergeObjSum(a: Subjects, b: Subjects) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup(data: SubmoduleData): void {
|
function setup(data: SubmoduleData): void {
|
||||||
const { app /* userDB, url, publicdirs, moduleSpecificData */ } = data
|
const { app } = data
|
||||||
|
|
||||||
app.get('/ranklist', (req: Request, res) => {
|
app.get('/ranklist', (req: Request, res) => {
|
||||||
logger.LogReq(req)
|
logger.LogReq(req)
|
||||||
|
|
|
@ -74,7 +74,7 @@ interface Todos {
|
||||||
const todosFile = 'data/todos.json'
|
const todosFile = 'data/todos.json'
|
||||||
|
|
||||||
function setup(data: SubmoduleData): void {
|
function setup(data: SubmoduleData): void {
|
||||||
const { app /* userDB, url, publicdirs, moduleSpecificData */ } = data
|
const { app } = data
|
||||||
|
|
||||||
app.get('/voteTodo', (req: Request, res: Response) => {
|
app.get('/voteTodo', (req: Request, res: Response) => {
|
||||||
logger.LogReq(req)
|
logger.LogReq(req)
|
||||||
|
|
|
@ -83,7 +83,7 @@ function listDir(publicDir: string, subdir: string, userFilesDir: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup(data: SubmoduleData): void {
|
function setup(data: SubmoduleData): void {
|
||||||
const { app, /* userDB, url, */ publicdirs /* moduleSpecificData */ } = data
|
const { app, publicdirs } = data
|
||||||
|
|
||||||
app.use((req: Request, _res, next) => {
|
app.use((req: Request, _res, next) => {
|
||||||
// /userFiles/test/2021-04-28_10-59.png
|
// /userFiles/test/2021-04-28_10-59.png
|
||||||
|
|
|
@ -90,7 +90,7 @@ function createDefaultUser(userDb: Database) {
|
||||||
const validationTokenName = 'qmining' // readValidationTokenName()
|
const validationTokenName = 'qmining' // readValidationTokenName()
|
||||||
|
|
||||||
function setup(data: SubmoduleData): Submodule {
|
function setup(data: SubmoduleData): Submodule {
|
||||||
const { app, userDB, url /* publicdirs, moduleSpecificData */ } = data
|
const { app, userDB, url } = data
|
||||||
const domain: any = url
|
const domain: any = url
|
||||||
logger.DebugLog(`Cookie domain: ${domain}`, 'cookie', 1)
|
logger.DebugLog(`Cookie domain: ${domain}`, 'cookie', 1)
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@ import { LinksSchema, validateJSON } from '../../types/typeSchemas'
|
||||||
let publicdirs: string[] = []
|
let publicdirs: string[] = []
|
||||||
let userDB: Database
|
let userDB: Database
|
||||||
let nextdir = ''
|
let nextdir = ''
|
||||||
let domain = ''
|
|
||||||
|
|
||||||
function GetApp(): ModuleType {
|
function GetApp(): ModuleType {
|
||||||
app.use(
|
app.use(
|
||||||
|
@ -112,18 +111,10 @@ function GetApp(): ModuleType {
|
||||||
// REDIRECTS
|
// REDIRECTS
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
|
||||||
// to be backwards compatible
|
|
||||||
app.get('/ask', function (req: Request, res) {
|
|
||||||
logger.DebugLog(`Qmining module ask redirect`, 'ask', 1)
|
|
||||||
res.redirect(
|
|
||||||
`http://${domain}/ask?q=${req.query.q}&subj=${req.query.subj}&data=${req.query.data}`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
const simpleRedirects = [
|
const simpleRedirects = [
|
||||||
{
|
{
|
||||||
from: '/install',
|
from: '/install',
|
||||||
to: `https://${domain}/moodle-test-userscript/stable.user.js`,
|
to: `/moodle-test-userscript/stable.user.js`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
from: '/servergit',
|
from: '/servergit',
|
||||||
|
@ -163,15 +154,15 @@ function GetApp(): ModuleType {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
from: '/allqr',
|
from: '/allqr',
|
||||||
to: `https://${domain}/api/allqr.txt`,
|
to: `/api/allqr.txt`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
from: '/allqr.txt',
|
from: '/allqr.txt',
|
||||||
to: `https://${domain}/api/allqr.txt`,
|
to: `/api/allqr.txt`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
from: '/infos',
|
from: '/infos',
|
||||||
to: `https://${domain}/api/infos?version=true&motd=true&subjinfo=true`,
|
to: `/api/infos?version=true&motd=true&subjinfo=true`,
|
||||||
nolog: true,
|
nolog: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -261,7 +252,6 @@ export default {
|
||||||
name: 'Qmining',
|
name: 'Qmining',
|
||||||
getApp: GetApp,
|
getApp: GetApp,
|
||||||
setup: (data: SetupData): void => {
|
setup: (data: SetupData): void => {
|
||||||
domain = data.url
|
|
||||||
userDB = data.userDB
|
userDB = data.userDB
|
||||||
publicdirs = data.publicdirs
|
publicdirs = data.publicdirs
|
||||||
nextdir = data.nextdir
|
nextdir = data.nextdir
|
||||||
|
|
|
@ -239,7 +239,7 @@ Object.keys(modules).forEach(function (key) {
|
||||||
|
|
||||||
if (mod.setup) {
|
if (mod.setup) {
|
||||||
mod.setup({
|
mod.setup({
|
||||||
url: constants.domain,
|
url: constants.domain, // used by api.ts -> userManagement.ts -> cookies
|
||||||
userDB: userDB,
|
userDB: userDB,
|
||||||
publicdirs: module.publicdirs,
|
publicdirs: module.publicdirs,
|
||||||
nextdir: module.nextdir,
|
nextdir: module.nextdir,
|
||||||
|
@ -267,7 +267,7 @@ app.get('*', (req, res) => {
|
||||||
if (req.is('application/json')) {
|
if (req.is('application/json')) {
|
||||||
res.status(404).end()
|
res.status(404).end()
|
||||||
} else {
|
} else {
|
||||||
res.status(404).render('404', { domain: constants.domain })
|
res.status(404).render('404')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<html>
|
<html>
|
||||||
<body bgcolor="#222426">
|
<body bgcolor="#222426">
|
||||||
<head>
|
<head>
|
||||||
<title>Qmining | <%= domain %> - Login</title>
|
<title>Qmining - Login</title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=0.6" />
|
<meta name="viewport" content="width=device-width, initial-scale=0.6" />
|
||||||
<style>
|
<style>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue