forked from OpenWF/SpaceNinjaServer
feat: config refactoring (#219)
This commit is contained in:
parent
7fa9d08a4d
commit
64b4523b39
13
.env.example
13
.env.example
@ -1,15 +1,4 @@
|
||||
MONGODB_URL='mongodb://127.0.0.1:27017/openWF'
|
||||
|
||||
#DOCKER ONLY
|
||||
# Docker may need a .env file for the following settings:
|
||||
DATABASE_PORT=27017
|
||||
DATABASE_USERNAME=root
|
||||
DATABASE_PASSWORD=database
|
||||
#DOCKER ONLY END
|
||||
|
||||
# save logs to file
|
||||
LOG_FILES=true
|
||||
#possible log levels: { fatal: 0, error: 1, warn: 2, info: 3, http: 4, debug: 5, trace: 6 }
|
||||
LOG_LEVEL=trace
|
||||
|
||||
|
||||
|
||||
|
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@ -15,4 +15,5 @@ jobs:
|
||||
with:
|
||||
node-version: "20.x"
|
||||
- run: npm ci
|
||||
- run: cp config.json.example config.json
|
||||
- run: npm run build
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@
|
||||
/build
|
||||
|
||||
/.env
|
||||
/config.json
|
||||
/static/data/*.bin
|
||||
yarn.lock
|
||||
/tmp
|
||||
|
@ -1,8 +1,12 @@
|
||||
{
|
||||
"mongodbUrl": "mongodb://127.0.0.1:27017/openWF",
|
||||
"logger": {
|
||||
"files": true,
|
||||
"level": "trace",
|
||||
"__valid_levels": "fatal, error, warn, info, http, debug, trace"
|
||||
},
|
||||
"myAddress": "localhost",
|
||||
"autoCreateAccount": true,
|
||||
"buildLabel": "2024.05.03.11.35/g98E42og3EdWxS0UueO+PQ",
|
||||
"matchmakingBuildId": "6945333874579955227",
|
||||
"version": "35.5.11",
|
||||
"skipStoryModeChoice": true,
|
||||
"skipTutorial": true,
|
||||
"unlockAllScans": true,
|
12
package-lock.json
generated
12
package-lock.json
generated
@ -10,7 +10,6 @@
|
||||
"license": "GNU",
|
||||
"dependencies": {
|
||||
"copyfiles": "^2.4.1",
|
||||
"dotenv": "^16.1.3",
|
||||
"express": "^5.0.0-beta.3",
|
||||
"mongoose": "^8.1.1",
|
||||
"warframe-items": "^1.1261.19",
|
||||
@ -1493,17 +1492,6 @@
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.1.3",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.1.3.tgz",
|
||||
"integrity": "sha512-FYssxsmCTtKL72fGBSvb1K9dRz0/VZeWqFme/vSb7r7323x4CRaHu4LvQ5JG3+s6yt2YPbBrkpiEODktfyjI9A==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/motdotla/dotenv?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/dynamic-dedupe": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/dynamic-dedupe/-/dynamic-dedupe-0.3.0.tgz",
|
||||
|
@ -14,7 +14,6 @@
|
||||
"license": "GNU",
|
||||
"dependencies": {
|
||||
"copyfiles": "^2.4.1",
|
||||
"dotenv": "^16.1.3",
|
||||
"express": "^5.0.0-beta.3",
|
||||
"mongoose": "^8.1.1",
|
||||
"warframe-items": "^1.1261.19",
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { RequestHandler } from "express";
|
||||
import config from "@/config.json";
|
||||
import { config } from "@/src/services/configService";
|
||||
import { getInventory } from "@/src/services/inventoryService";
|
||||
import { parseString } from "@/src/helpers/general";
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { RequestHandler } from "express";
|
||||
import config from "@/config.json";
|
||||
import { config } from "@/src/services/configService";
|
||||
import allShipFeatures from "@/static/fixed_responses/allShipFeatures.json";
|
||||
import { parseString } from "@/src/helpers/general";
|
||||
import { getPersonalRooms } from "@/src/services/personalRoomsService";
|
||||
|
@ -2,7 +2,7 @@
|
||||
import { toInventoryResponse } from "@/src/helpers/inventoryHelpers";
|
||||
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
|
||||
import { Request, RequestHandler, Response } from "express";
|
||||
import config from "@/config.json";
|
||||
import { config } from "@/src/services/configService";
|
||||
import allMissions from "@/static/fixed_responses/allMissions.json";
|
||||
import allQuestKeys from "@/static/fixed_responses/allQuestKeys.json";
|
||||
import allShipDecorations from "@/static/fixed_responses/allShipDecorations.json";
|
||||
|
@ -1,13 +1,14 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
import config from "@/config.json";
|
||||
import { config } from "@/src/services/configService";
|
||||
import buildConfig from "@/static/data/buildConfig.json";
|
||||
|
||||
import { toLoginRequest } from "@/src/helpers/loginHelpers";
|
||||
import { Account } from "@/src/models/loginModel";
|
||||
import { createAccount, isCorrectPassword } from "@/src/services/loginService";
|
||||
import { ILoginResponse } from "@/src/types/loginTypes";
|
||||
import { DTLS, groups, HUB, IRC, Nonce, NRS, platformCDNs } from "@/static/fixed_responses/login_static";
|
||||
import { DTLS, groups, HUB, Nonce, platformCDNs } from "@/static/fixed_responses/login_static";
|
||||
import { logger } from "@/src/utils/logger";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
@ -39,12 +40,12 @@ const loginController: RequestHandler = async (request, response) => {
|
||||
Groups: groups,
|
||||
platformCDNs: platformCDNs,
|
||||
Nonce: Nonce,
|
||||
NRS: NRS,
|
||||
NRS: [config.myAddress],
|
||||
DTLS: DTLS,
|
||||
IRC: IRC,
|
||||
IRC: [config.myAddress],
|
||||
HUB: HUB,
|
||||
BuildLabel: config.buildLabel,
|
||||
MatchmakingBuildId: config.matchmakingBuildId
|
||||
BuildLabel: buildConfig.buildLabel,
|
||||
MatchmakingBuildId: buildConfig.matchmakingBuildId
|
||||
};
|
||||
|
||||
response.json(newLoginResponse);
|
||||
@ -68,12 +69,12 @@ const loginController: RequestHandler = async (request, response) => {
|
||||
Groups: groups,
|
||||
platformCDNs: platformCDNs,
|
||||
Nonce: Nonce,
|
||||
NRS: NRS,
|
||||
NRS: [config.myAddress],
|
||||
DTLS: DTLS,
|
||||
IRC: IRC,
|
||||
IRC: [config.myAddress],
|
||||
HUB: HUB,
|
||||
BuildLabel: config.buildLabel,
|
||||
MatchmakingBuildId: config.matchmakingBuildId
|
||||
BuildLabel: buildConfig.buildLabel,
|
||||
MatchmakingBuildId: buildConfig.matchmakingBuildId
|
||||
};
|
||||
|
||||
response.json(newLoginResponse);
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { RequestHandler } from "express";
|
||||
import worldState from "@/static/fixed_responses/worldState.json";
|
||||
import config from "@/config.json";
|
||||
import buildConfig from "@/static/data/buildConfig.json";
|
||||
|
||||
const worldStateController: RequestHandler = (_req, res) => {
|
||||
res.json({
|
||||
...worldState,
|
||||
BuildLabel: config.buildLabel,
|
||||
BuildLabel: buildConfig.buildLabel,
|
||||
Time: Math.round(Date.now() / 1000)
|
||||
});
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
|
||||
import { IStatsView } from "@/src/types/statTypes";
|
||||
import config from "@/config.json";
|
||||
import { config } from "@/src/services/configService";
|
||||
import view from "@/static/fixed_responses/view.json";
|
||||
import allScans from "@/static/fixed_responses/allScans.json";
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import express from "express";
|
||||
import config from "@/config.json";
|
||||
import buildConfig from "@/static/data/buildConfig.json";
|
||||
|
||||
const cacheRouter = express.Router();
|
||||
|
||||
@ -12,7 +12,7 @@ cacheRouter.get("/B.Cache.Windows_en.bin*", (_req, res) => {
|
||||
});
|
||||
|
||||
cacheRouter.get(/^\/origin\/[a-zA-Z0-9]+\/[0-9]+\/H\.Cache\.bin.*$/, (_req, res) => {
|
||||
res.sendFile(`static/data/H.Cache_${config.version}.bin`, { root: "./" });
|
||||
res.sendFile(`static/data/H.Cache_${buildConfig.version}.bin`, { root: "./" });
|
||||
});
|
||||
|
||||
export { cacheRouter };
|
||||
|
24
src/services/configService.ts
Normal file
24
src/services/configService.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import rawConfig from "@/config.json";
|
||||
|
||||
interface IConfig {
|
||||
mongodbUrl: string;
|
||||
logger: ILoggerConfig;
|
||||
myAddress: string;
|
||||
autoCreateAccount?: boolean;
|
||||
skipStoryModeChoice?: boolean;
|
||||
skipTutorial?: boolean;
|
||||
unlockAllScans?: boolean;
|
||||
unlockAllMissions?: boolean;
|
||||
unlockAllQuests?: boolean;
|
||||
infiniteResources?: boolean;
|
||||
unlockallShipFeatures?: boolean;
|
||||
unlockAllShipDecorations?: boolean;
|
||||
unlockAllFlavourItems?: boolean;
|
||||
}
|
||||
|
||||
interface ILoggerConfig {
|
||||
files: boolean;
|
||||
level: string; // "fatal" | "error" | "warn" | "info" | "http" | "debug" | "trace";
|
||||
}
|
||||
|
||||
export const config: IConfig = rawConfig;
|
@ -1,6 +1,6 @@
|
||||
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
|
||||
import new_inventory from "@/static/fixed_responses/postTutorialInventory.json";
|
||||
import config from "@/config.json";
|
||||
import { config } from "@/src/services/configService";
|
||||
import { Types } from "mongoose";
|
||||
import { ISuitClient } from "@/src/types/inventoryTypes/SuitTypes";
|
||||
import { SlotNames } from "@/src/types/purchaseTypes";
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { logger } from "@/src/utils/logger";
|
||||
import * as dotenv from "dotenv";
|
||||
import { config } from "@/src/services/configService";
|
||||
import mongoose from "mongoose";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const url = process.env.MONGODB_URL;
|
||||
const url = config.mongodbUrl;
|
||||
|
||||
if (url === undefined) {
|
||||
throw new Error("MONGODB_URL not found. Make sure you have a .env file in the root of the project!");
|
||||
|
@ -1,11 +1,9 @@
|
||||
import { createLogger, format, transports, Logger, LeveledLogMethod, addColors } from "winston";
|
||||
import "winston-daily-rotate-file";
|
||||
import * as dotenv from "dotenv";
|
||||
import { config } from "@/src/services/configService";
|
||||
import * as util from "util";
|
||||
import { isEmptyObject } from "@/src/helpers/general";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
// const combineMessageAndSplat = () => {
|
||||
// return {
|
||||
// transform: (info: any, _opts: any) => {
|
||||
@ -72,7 +70,7 @@ const consoleLog = new transports.Console({
|
||||
)
|
||||
});
|
||||
|
||||
const transportOptions = process.env.LOG_FILES === "true" ? [consoleLog, errorLog, combinedLog] : [consoleLog];
|
||||
const transportOptions = config.logger.files ? [consoleLog, errorLog, combinedLog] : [consoleLog];
|
||||
|
||||
//possible log levels: { fatal: 0, error: 1, warn: 2, info: 3, http: 4, debug: 5, trace: 6 },
|
||||
const logLevels = {
|
||||
@ -98,7 +96,7 @@ const logLevels = {
|
||||
|
||||
export const logger = createLogger({
|
||||
levels: logLevels.levels,
|
||||
level: process.env.LOG_LEVEL,
|
||||
level: config.logger.level,
|
||||
defaultMeta: { version: process.env.npm_package_version },
|
||||
transports: transportOptions
|
||||
}) as Logger & Record<keyof typeof logLevels.levels, LeveledLogMethod>;
|
||||
|
5
static/data/buildConfig.json
Normal file
5
static/data/buildConfig.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"version": "35.5.11",
|
||||
"buildLabel": "2024.05.03.11.35/g98E42og3EdWxS0UueO+PQ",
|
||||
"matchmakingBuildId": "6945333874579955227"
|
||||
}
|
@ -24,10 +24,6 @@ export const platformCDNs = [
|
||||
|
||||
export const Nonce = 1231231233;
|
||||
|
||||
export const NRS = ["localhost"];
|
||||
|
||||
export const DTLS = 99;
|
||||
|
||||
export const IRC = ["localhost"];
|
||||
|
||||
export const HUB = "https://arbiter.warframe.com/api/";
|
||||
|
Loading…
x
Reference in New Issue
Block a user