parent
5f6c5633e6
commit
afec88082b
@ -0,0 +1,21 @@ |
||||
"use strict"; |
||||
|
||||
/** |
||||
* Recursively overwrites 1 settings object with another. |
||||
* Ported from PHP: https://gist.github.com/00f1b9b1fd6ca0610b780587f11ede4e#file-applysettings-php
|
||||
* @param {object} def The default settings object to overwrite. |
||||
* @param {object} custom The settings to use when overwriting. |
||||
*/ |
||||
function apply_settings(def, custom) { |
||||
// Loop over each of the custom settings
|
||||
for(let key in custom) { |
||||
// If the property isn't an object, then it's probably a setting
|
||||
// We should overwrite the existing default setting with the custom one.
|
||||
if(typeof custom[key] != "object") |
||||
def[key] = custom[key]; |
||||
else // It's an object! We should recurse over it.
|
||||
apply_settings(def[key], custom[key]); |
||||
} |
||||
} |
||||
|
||||
export default apply_settings; |
@ -0,0 +1,18 @@ |
||||
"use strict"; |
||||
|
||||
import a from 'awilix'; |
||||
|
||||
import database_init from '../bootstrap/database_init.mjs'; |
||||
import TTNAppServer from '../ttn-app-server/TTNAppServer.mjs'; |
||||
|
||||
const c = a.createContainer({ |
||||
injectionMode: a.InjectionMode.PROXY |
||||
}); |
||||
|
||||
c.register({ |
||||
database: a.asFunction(database_init).singleton(), |
||||
TTNAppServer: a.asClass(TTNAppServer), |
||||
}); |
||||
c.loadModules( |
||||
|
||||
export default c; |
@ -0,0 +1,26 @@ |
||||
"use strict"; |
||||
|
||||
import fs from 'fs'; |
||||
|
||||
import toml from '@iarna/toml'; |
||||
|
||||
import c from './container.mjs'; |
||||
import apply_settings from './Helpers/apply_settings.mjs'; |
||||
|
||||
|
||||
let filename_default = "../settings.default.toml", |
||||
filename_custom = "../../settings.toml"; |
||||
|
||||
if(!fs.existsSync(filename_custom)) |
||||
fs.writeFileSync(filename_custom, `# Custom settings file. This file overrides server/settings.default.toml - refer there of example of settings you can override.\n\n`); |
||||
|
||||
let settings = toml.parse(fs.readFileSync(filename_default, "utf-8")), |
||||
settings_override = toml.parse(fs.readFileSync("../../settings.custom.toml", "utf-8")); |
||||
|
||||
apply_settings(settings, settings_override); |
||||
|
||||
c.register({ |
||||
settings: a.asValue(settings) |
||||
}); |
||||
|
||||
export default settings; |
@ -0,0 +1,16 @@ |
||||
# Default settings file. |
||||
# |
||||
# DO NOT EDIT THIS FILE. Instead edit ../settings.toml (or create it if it doesn't exist yet). |
||||
|
||||
program_name = "LoRaWAN Signal Mapper" |
||||
version = "v0.1" |
||||
description = "assists in mapping LoRaWAN signal coverage" |
||||
|
||||
[database] |
||||
### Database settings ### |
||||
|
||||
# The path to the sqlite database file. If it doesn't exist it will be created. |
||||
filename = "lorawan.sqlite" |
||||
|
||||
# The options to pass to better-sqlite3. You probably don't need to change this. |
||||
[database.options] |
Loading…
Reference in new issue