chore: replace nosettings and mock by sandbox
This commit is contained in:
@@ -88,7 +88,7 @@ async function retry(func, {retries = 1, delay = 0} = {}) {
|
||||
}
|
||||
|
||||
//Load configuration
|
||||
const {conf, Plugins, Templates} = await setup({log:false, nosettings:true, community:{templates:core.getInput("setup_community_templates")}})
|
||||
const {conf, Plugins, Templates} = await setup({log:false, community:{templates:core.getInput("setup_community_templates")}})
|
||||
const {metadata} = conf
|
||||
conf.settings.extras = {default:true}
|
||||
info("Setup", "complete")
|
||||
@@ -288,7 +288,7 @@ async function retry(func, {retries = 1, delay = 0} = {}) {
|
||||
await new Promise(async (solve, reject) => {
|
||||
let stdout = ""
|
||||
setTimeout(() => reject("Timeout while waiting for Insights webserver"), 5 * 60 * 1000)
|
||||
const web = await processes.spawn("node", ["/metrics/source/app/web/index.mjs"], {env:{...process.env, NO_SETTINGS:true}})
|
||||
const web = await processes.spawn("node", ["/metrics/source/app/web/index.mjs"], {env:{...process.env}})
|
||||
web.stdout.on("data", data => (console.debug(`web > ${data}`), stdout += data, /Server ready !/.test(stdout) ? solve() : null))
|
||||
web.stderr.on("data", data => console.debug(`web > ${data}`))
|
||||
})
|
||||
|
||||
@@ -13,7 +13,7 @@ const Templates = {}
|
||||
const Plugins = {}
|
||||
|
||||
/**Setup */
|
||||
export default async function({log = true, nosettings = false, community = {}} = {}) {
|
||||
export default async function({log = true, sandbox = false, community = {}} = {}) {
|
||||
//Paths
|
||||
const __metrics = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "../../..")
|
||||
const __statics = path.join(__metrics, "source/app/web/statics")
|
||||
@@ -42,8 +42,8 @@ export default async function({log = true, nosettings = false, community = {}} =
|
||||
//Load settings
|
||||
logger("metrics/setup > load settings.json")
|
||||
if (fs.existsSync(__settings)) {
|
||||
if (nosettings)
|
||||
logger("metrics/setup > load settings.json > skipped because no settings is enabled")
|
||||
if (sandbox)
|
||||
logger("metrics/setup > load settings.json > skipped because in sandbox is enabled")
|
||||
else {
|
||||
conf.settings = JSON.parse(`${await fs.promises.readFile(__settings)}`)
|
||||
logger("metrics/setup > load settings.json > success")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import app from "./instance.mjs"
|
||||
;(async function() {
|
||||
await app({mock:process.env.USE_MOCKED_DATA, nosettings:process.env.NO_SETTINGS})
|
||||
await app({sandbox:process.env.SANDBOX})
|
||||
})()
|
||||
|
||||
@@ -12,11 +12,20 @@ import presets from "../metrics/presets.mjs"
|
||||
import setup from "../metrics/setup.mjs"
|
||||
|
||||
/**App */
|
||||
export default async function({mock, nosettings} = {}) {
|
||||
export default async function({sandbox} = {}) {
|
||||
//Load configuration settings
|
||||
const {conf, Plugins, Templates} = await setup({nosettings})
|
||||
const {conf, Plugins, Templates} = await setup({sandbox})
|
||||
const {token, maxusers = 0, restricted = [], debug = false, cached = 30 * 60 * 1000, port = 3000, ratelimiter = null, plugins = null} = conf.settings
|
||||
mock = mock || conf.settings.mocked
|
||||
const mock = sandbox || conf.settings.mocked
|
||||
|
||||
//Sandbox mode
|
||||
if (sandbox) {
|
||||
console.debug("metrics/app > sandbox mode is specified, enabling advanced features")
|
||||
conf.settings.extras = conf.settings.extras ?? {}
|
||||
conf.settings.extras.default = true
|
||||
conf.settings["plugins.default"] = true
|
||||
conf.settings.optimize = true
|
||||
}
|
||||
|
||||
//Process mocking and default plugin state
|
||||
for (const plugin of Object.keys(Plugins).filter(x => !["base", "core"].includes(x))) {
|
||||
|
||||
Reference in New Issue
Block a user