mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
added support for DOMAIN env var insted of file
This commit is contained in:
parent
7d1bddd7e2
commit
d310895fcb
9 changed files with 53 additions and 29 deletions
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"savedQuestionsFileName": "savedQuestions.json"
|
||||
}
|
15
src/constants.ts
Normal file
15
src/constants.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { paths } from './utils/files'
|
||||
import utils from './utils/utils'
|
||||
|
||||
const domain = process.env.DOMAIN || utils.ReadFile(paths.domainFile).trim()
|
||||
|
||||
if (!domain) {
|
||||
throw new Error(
|
||||
`Domain is undefined! Should be set with 'DOMAIN' environment variable, or written to '${paths.domainFile}'`
|
||||
)
|
||||
}
|
||||
|
||||
export default {
|
||||
savedQuestionsFileName: 'savedQuestions.json',
|
||||
domain: domain,
|
||||
}
|
|
@ -24,10 +24,7 @@ import type { Database } from 'better-sqlite3'
|
|||
|
||||
import logger from '../utils/logger'
|
||||
import dbtools from '../utils/dbtools'
|
||||
import { paths } from '../utils/files'
|
||||
import utils from '../utils/utils'
|
||||
|
||||
const domain = utils.ReadFile(paths.domainFile).trim()
|
||||
import constants from '../constants'
|
||||
|
||||
interface Options {
|
||||
userDB: Database
|
||||
|
@ -56,7 +53,7 @@ function renderLogin(req: Request, res: Response) {
|
|||
} else {
|
||||
res.render('login', {
|
||||
useHttp: process.env.NS_NO_HTTPS_FORCE,
|
||||
domain: domain,
|
||||
domain: constants.domain,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,6 +96,7 @@ interface SyncDataRes {
|
|||
function updateThirdPartyPeers(
|
||||
newVal: Omit<PeerInfo, 'publicKey' | 'name' | 'contact'>[]
|
||||
) {
|
||||
// TODO: check if thirdPartyPeersFile exists!
|
||||
const prevVal = utils.ReadJSON<PeerInfo[]>(paths.thirdPartyPeersFile)
|
||||
const dataToWrite = newVal.reduce((acc, peer) => {
|
||||
const isIncluded = acc.find((x) => {
|
||||
|
@ -963,6 +964,7 @@ function setup(data: SubmoduleData): Submodule {
|
|||
remoteInfo: getSelfInfo(),
|
||||
}
|
||||
|
||||
// TODO: hostname is invalid, should be remote host?
|
||||
let hostToLog = req.hostname
|
||||
if (remoteHost) {
|
||||
const remotePeerInfo = peers.find((peer) => {
|
||||
|
@ -998,6 +1000,7 @@ function setup(data: SubmoduleData): Submodule {
|
|||
)
|
||||
if (remoteHost.includes(':')) {
|
||||
const [host, port] = remoteHost.split(':')
|
||||
// TODO: add public key
|
||||
updateThirdPartyPeers([
|
||||
{
|
||||
host: host,
|
||||
|
|
|
@ -60,7 +60,7 @@ import {
|
|||
SearchResultQuestion,
|
||||
} from '../../../utils/qdbUtils'
|
||||
import { paths } from '../../../utils/files'
|
||||
import constants from '../../../constants.json'
|
||||
import constants from '../../../constants'
|
||||
import {
|
||||
isJsonValidAndLogError,
|
||||
TestUsersSchema,
|
||||
|
|
|
@ -42,6 +42,7 @@ import dbtools from './utils/dbtools'
|
|||
import reqlogger from './middlewares/reqlogger.middleware'
|
||||
import idStats from './utils/ids'
|
||||
import { paths, validateFiles } from './utils/files'
|
||||
import constants from './constants'
|
||||
|
||||
const logFile = paths.logDir + logger.logFileName
|
||||
const vlogFile = paths.vlogDir + logger.logFileName
|
||||
|
@ -226,8 +227,6 @@ app.use(
|
|||
})
|
||||
)
|
||||
|
||||
const domain = utils.ReadFile(paths.domainFile).trim()
|
||||
|
||||
Object.keys(modules).forEach(function (key) {
|
||||
const module = modules[key]
|
||||
try {
|
||||
|
@ -240,7 +239,7 @@ Object.keys(modules).forEach(function (key) {
|
|||
|
||||
if (mod.setup) {
|
||||
mod.setup({
|
||||
url: domain,
|
||||
url: constants.domain,
|
||||
userDB: userDB,
|
||||
publicdirs: module.publicdirs,
|
||||
nextdir: module.nextdir,
|
||||
|
@ -268,7 +267,7 @@ app.get('*', (req, res) => {
|
|||
if (req.is('application/json')) {
|
||||
res.status(404).end()
|
||||
} else {
|
||||
res.status(404).render('404', { domain: domain })
|
||||
res.status(404).render('404', { domain: constants.domain })
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -124,9 +124,8 @@ export const files = {
|
|||
|
||||
domainFile: {
|
||||
path: 'data/domain',
|
||||
errorIfMissing: true,
|
||||
description:
|
||||
'server domain for cookies and stuff, for ex.: "frylabs.net", no "http://" and things like that, just the domain',
|
||||
'server domain for cookies and stuff, for ex.: "qmining.com", no "http://" and things like that, just the domain',
|
||||
},
|
||||
// --------------------------------------------------------------------------------
|
||||
// stats files
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue