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