From 5639e01815ba25e5c50d2c874ff478946bad8984 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Wed, 25 Jan 2023 00:28:44 +0000 Subject: [PATCH] add vars.js.template, use vars config items in api --- .gitignore | 3 ++- index.js | 11 +++++------ vars.js.template | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 vars.js.template diff --git a/.gitignore b/.gitignore index e35ca61..9790e9b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ **/package-lock.json -**/node_modules \ No newline at end of file +**/node_modules +**/vars.js \ No newline at end of file diff --git a/index.js b/index.js index fdd46ae..c970f6e 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,8 @@ const helmet = require("helmet"); const morgan = require("morgan"); const https = require("https"); var package = require("./package.json"); -const { request } = require("http"); + +const {pveAPI, listenPort} = require("./vars.js") const app = express(); app.use(helmet()); @@ -55,10 +56,8 @@ function checkAuth (cookies, callback, vmpath = null) { function requestPVE (path, method, cookies, callback, body = null, token = null) { let prms = new URLSearchParams(body); + let url = `${pveAPI}${path}`; let content = { - hostname: "pve.tronnet.net", - port: 443, - path: `/api2/json${path}`, method: method, mode: "cors", credentials: "include", @@ -84,7 +83,7 @@ function requestPVE (path, method, cookies, callback, body = null, token = null) headers: '' }; - const request = https.request(content); + const request = https.request(url, content); request.on('error', reject); request.on('response', response => { @@ -109,6 +108,6 @@ function requestPVE (path, method, cookies, callback, body = null, token = null) ); } -app.listen(80, () => { +app.listen(listenPort, () => { console.log("listening on port 80"); }); \ No newline at end of file diff --git a/vars.js.template b/vars.js.template new file mode 100644 index 0000000..115d118 --- /dev/null +++ b/vars.js.template @@ -0,0 +1,4 @@ +const pveAPI = ""; +const listenPort = 80; + +module.exports = {pveAPI, listenPort}; \ No newline at end of file