XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

feat: extended database configuration (#4192)

Now the version/line of the embedded MongoDB can be configured alongside the data path. The default version in config-vanilla is 7.0, while keeping 8.0 when migrating configs due to lack of a downgrade path. The reason for changing the default to 7.0 is because it's not EOL yet and has no known issues with Windows 10, unlike 8.0. (We might also wanna keep alternatives like FerretDB in mind.) Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/4192 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

a07f9083
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

6 个文件 +36 -11
Modified README.md +1 -1
@@ -13,7 +13,7 @@ To get an idea of what functionality you can expect to be missing [have a look t
13 13 SpaceNinjaServer requires a `config.json`. To set it up, you can copy the [config-vanilla.json](config-vanilla.json), which has most cheats disabled.
14 14
15 15 - `skipTutorial` affects only newly created accounts, so you may wish to change it before logging in for the first time.
16 - `mongodbUrl` defaults to a `file://` URI which starts up an embedded mongod, but can be `mongodb://127.0.0.1:27017/openWF` if you have a system-wide mongod installation.
16 - `database` defaults to an object to configure the _embedded_ mongod, but can be a string like `"mongodb://127.0.0.1:27017/openWF"` to simply connect to an existing MongoDB instance.
17 17 - `logger.level` can be `fatal`, `error`, `warn`, `info`, `http`, `debug`, or `trace`.
18 18 - `bindAddress`, `httpPort`, `httpsPort` are related to how SpaceNinjaServer is reached on the network. Under Docker, these options are unchangable; modify your `docker-compose.yml`, instead.
19 19 - `ircExecutable` and `hubExecutable` can be provided with relative paths to executables which will be ran as child processes of SpaceNinjaServer.
Modified config-vanilla.json +4 -1
@@ -1,5 +1,8 @@
1 1 {
2 "mongodbUrl": "file://./database",
2 "database": {
3 "engine": "MongoDB 7.0",
4 "dbPath": "./database"
5 },
3 6 "logger": {
4 7 "files": true,
5 8 "level": "trace",
Modified docker-entrypoint.sh +1 -1
@@ -2,7 +2,7 @@
2 2 set -e
3 3
4 4 if [ ! -f conf/config.json ]; then
5 jq --arg value "mongodb://mongodb:27017/openWF" '.mongodbUrl = $value | del(.bindAddress) | del(.httpPort) | del(.httpsPort)' /app/config-vanilla.json > /app/conf/config.json
5 jq --arg value "mongodb://mongodb:27017/openWF" '.database = $value | del(.bindAddress) | del(.httpPort) | del(.httpsPort)' /app/config-vanilla.json > /app/conf/config.json
6 6 fi
7 7
8 8 exec npm run raw -- --configPath conf/config.json --docker
Modified src/index.ts +6 -6
@@ -37,14 +37,14 @@ fs.readFile(path.join(repoDir, "BUILD_DATE"), "utf-8", (err, data) => {
37 37 }
38 38 });
39 39
40 let mongodUri = config.mongodbUrl;
41 if (mongodUri.startsWith("file://")) {
42 let dataDir = path.resolve(mongodUri.substring("file://".length));
43 if (dataDir.substring(0, 1) == "/" && process.platform == "win32") {
44 dataDir = dataDir.substring(1); // Absolute path on Windows must not start with /
45 }
40 let mongodUri = config.database;
41 if (typeof mongodUri != "string") {
42 const dataDir = path.resolve(mongodUri.dbPath);
46 43 fs.mkdirSync(dataDir, { recursive: true });
47 44 const mongod = await MongoMemoryServer.create({
45 binary: {
46 version: mongodUri.engine == "MongoDB 8.0" ? undefined : "7.0.34" // Check https://www.mongodb.com/docs/v7.0/release-notes/7.0/ for updates :)
47 },
48 48 instance: {
49 49 dbPath: dataDir,
50 50 port: 27017, // Prefer 27017
Modified src/services/configService.ts +8 -2
@@ -20,7 +20,13 @@ export interface IWebuiConfig {
20 20 }
21 21
22 22 export interface IConfig {
23 mongodbUrl: string;
23 /** @deprecated */ mongodbUrl?: string;
24 database:
25 | string
26 | {
27 engine: "MongoDB 7.0" | "MongoDB 8.0";
28 dbPath: string;
29 };
24 30 logger: {
25 31 files: boolean;
26 32 level: string; // "fatal" | "error" | "warn" | "info" | "http" | "debug" | "trace";
@@ -222,7 +228,7 @@ if (args.docker) {
222 228 export const configPath = path.join(repoDir, args.configPath ?? "config.json");
223 229
224 230 export const config: IConfig = {
225 mongodbUrl: "mongodb://127.0.0.1:27017/openWF",
231 database: "mongodb://127.0.0.1:27017/openWF",
226 232 logger: {
227 233 files: true,
228 234 level: "trace"
Modified src/services/configWatcherService.ts +16 -0
@@ -91,6 +91,22 @@ chokidar.watch(configPath).on("change", () => {
91 91
92 92 export const validateConfig = (): void => {
93 93 let modified = false;
94 if (config.mongodbUrl) {
95 if (config.mongodbUrl.startsWith("file://")) {
96 let dataDir = config.mongodbUrl.substring("file://".length);
97 if (dataDir.substring(0, 1) == "/" && process.platform == "win32") {
98 dataDir = dataDir.substring(1); // Absolute path on Windows must not start with /
99 }
100 config.database = {
101 engine: "MongoDB 8.0",
102 dbPath: dataDir
103 };
104 } else {
105 config.database = config.mongodbUrl;
106 }
107 delete config.mongodbUrl;
108 modified = true;
109 }
94 110 for (const key of configRemovedOptionsKeys) {
95 111 if (config[key as keyof IConfig] !== undefined) {
96 112 logger.debug(