Re-add config

This commit is contained in:
Mia 2021-10-11 21:12:01 -05:00
parent fdbf9198d0
commit 93e6bf862d
3 changed files with 55 additions and 8 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
node_modules
.dist
.eslintcache
.eslintcache
config/config.js

44
config/config-example.js Normal file
View File

@ -0,0 +1,44 @@
// MySQL DB settings.
exports.mysql = {
charset: "utf8",
database: "ps",
password: "uwu",
prefix: "",
user: "root",
};
// To use for password hashing.
exports.passwordSalt = 10;
// routes
exports.routes = {
client: "play.pokemonshowdown.com",
dex: "dex.pokemonshowdown.com",
replays: "replay.pokemonshowdown.com",
root: "pokemonshowdown.com",
users: "pokemonshowdown.com/users",
};
/**
* [Places to allow cors requests from, prefix to use][]
* @type {[RegExp, string][]}
*/
exports.cors = [
[/^http:\/\/smogon\.com$/, "smogon.com_"],
[/^http:\/\/www\.smogon\.com$/, "www.smogon.com_"],
[/^http:\/\/logs\.psim\.us$/, "logs.psim.us_"],
[/^http:\/\/logs\.psim\.us:8080$/, "logs.psim.us_"],
[/^http:\/\/[a-z0-9]+\.psim\.us$/, ""],
[/^http:\/\/play\.pokemonshowdown\.com$/, ""],
];
/**
* array of user IDs who will be given sysop powers on all servers they log into via this loginserver
* @type {string[]}
*/
exports.sysops = [];
// Private keys to use for validating assertions.
exports.privatekeys = [
"key here",
];

View File

@ -7,26 +7,26 @@
import * as fs from 'fs';
import * as path from 'path';
// @ts-ignore no typedef file
import * as defaults from '../config/ls-config-example';
import * as defaults from '../config/config-example';
export type Configuration = typeof defaults & {[k: string]: any};
export function load(invalidate = false): Configuration {
if (invalidate) delete require.cache[path.resolve(__dirname, '../config/ls-config')];
if (invalidate) delete require.cache[path.resolve(__dirname, '../config/config')];
const config: typeof defaults & {[k: string]: any} = defaults;
try {
Object.assign(config, require('../config/ls-config'));
Object.assign(config, require('../config/config'));
} catch (err: any) {
if (err.code !== 'MODULE_NOT_FOUND' && err.code !== 'ENOENT') throw err; // Should never happen
console.log("config.js doesn't exist - creating one with default settings...");
fs.writeFileSync(
path.resolve(__dirname, '../config/ls-config.js'),
fs.readFileSync(path.resolve(__dirname, '../config/ls-config-example.js'))
path.resolve(__dirname, '../config/config.js'),
fs.readFileSync(path.resolve(__dirname, '../config/config-example.js'))
);
}
// we really don't need to load from here afterwards since
// the configuration in the new ls-config will be the same as defaults.
// the configuration in the new config will be the same as defaults.
if (!config.routes) {
config.routes = require('../config/routes');
}
@ -39,5 +39,7 @@ export function load(invalidate = false): Configuration {
export const Config = load();
if (Config.watchconfig) {
fs.watchFile(require.resolve('../config/ls-config'), () => ({...Config, ...load(true)}));
fs.watchFile(require.resolve('../config/config'), () => {
Object.assign(Config, {...load(true)});
});
}