diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2024-06-22 19:37:37 +0300 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2024-06-22 19:37:37 +0300 |
commit | f4bfb970713a9599df193bc14348e2b406165392 (patch) | |
tree | d9b302953d1a973a40a03811105266229bc1bc4e | |
parent | 2043e733c9d1a2ad5c9f4a91a422b13656e12f05 (diff) | |
download | arching-kaos-tools-f4bfb970713a9599df193bc14348e2b406165392.tar.gz arching-kaos-tools-f4bfb970713a9599df193bc14348e2b406165392.tar.bz2 arching-kaos-tools-f4bfb970713a9599df193bc14348e2b406165392.zip |
api: Gets settings from ak-settings now
-rw-r--r-- | api/routes/default/index.js | 4 | ||||
-rw-r--r-- | api/settings/index.js | 33 |
2 files changed, 31 insertions, 6 deletions
diff --git a/api/routes/default/index.js b/api/routes/default/index.js index 19b069b..4026c0d 100644 --- a/api/routes/default/index.js +++ b/api/routes/default/index.js @@ -1,4 +1,6 @@ -const settings = require('../../settings'); +const rsettings = require('../../settings'); +const settings = rsettings(); + module.exports = (req, res) => { res.writeHead(404, { 'Content-Type': 'application/json'}); res.end(JSON.stringify({ diff --git a/api/settings/index.js b/api/settings/index.js index f71a66c..49b4084 100644 --- a/api/settings/index.js +++ b/api/settings/index.js @@ -1,6 +1,29 @@ -module.exports = { - PORT: 8610, - URL_PREFIX : "/v0", - DEF_PROTO : "http://", - LOCAL_IP : "127.0.0.1" +const { spawnSync } = require('child_process'); + +function get_api_bindToIP_value() +{ + const command = spawnSync("ak-settings", ["--get", "api.bindToIP"]); + var ip_to_bind_onto = command.stdout; + if ( command.status !== 0 ) { + return 1; + } else { + return ip_to_bind_onto; + } } + +function return_settings() +{ + const ip = get_api_bindToIP_value(); + const port = 8610; + const url_prefix = "/v0"; + const protocol = "http://"; + + return JSON.parse(JSON.stringify({ + "DEF_PROTO": `${protocol}`, + "LOCAL_IP": `${ip}`, + "PORT": `${port}`, + "URL_PREFIX": `${url_prefix}` + })); +} + +module.exports = return_settings; |