From 0176857a2cf9f8fd3db118807fbaa5b76ca7772c Mon Sep 17 00:00:00 2001 From: LouisLam Date: Mon, 12 Jul 2021 18:33:25 +0800 Subject: [PATCH] add ability to change the listening port and hostname --- package-lock.json | 8 ++++++-- package.json | 2 +- server/server.js | 11 +++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index d77efd9e1..3f7b3843b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,8 +1,7 @@ { "name": "uptime-kuma", - "version": "1.0.0", - "lockfileVersion": 1, "requires": true, + "lockfileVersion": 1, "dependencies": { "@babel/helper-validator-identifier": { "version": "7.14.5", @@ -243,6 +242,11 @@ "readable-stream": "^2.0.6" } }, + "args-parser": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/args-parser/-/args-parser-1.3.0.tgz", + "integrity": "sha512-If3Zi4BSjlQIJ9fgAhSiKi0oJtgMzSqh0H4wvl7XSeO16FKx7QqaHld8lZeEajPX7y1C5qKKeNgyrfyvmjmjUQ==" + }, "arr-diff": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-4.0.0.tgz", diff --git a/package.json b/package.json index b8ee4ed36..76c1538b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,5 @@ { "name": "uptime-kuma", - "version": "1.0.0", "scripts": { "dev": "vite --host", "start-server": "node server/server.js", @@ -12,6 +11,7 @@ }, "dependencies": { "@popperjs/core": "^2.9.2", + "args-parser": "^1.3.0", "axios": "^0.21.1", "bootstrap": "^5.0.0", "dayjs": "^1.10.4", diff --git a/server/server.js b/server/server.js index 7b340372e..a03e5acbb 100644 --- a/server/server.js +++ b/server/server.js @@ -12,6 +12,13 @@ const Monitor = require("./model/monitor"); const fs = require("fs"); const {getSettings} = require("./util-server"); const {Notification} = require("./notification") +const args = require('args-parser')(process.argv); + +console.log("args:") +console.log(args) + +const hostname = args.host || "0.0.0.0" +const port = args.port || 3001 app.use(express.json()) @@ -435,8 +442,8 @@ let needSetup = false; }); }); - server.listen(3001, () => { - console.log('Listening on 3001'); + server.listen(port, hostname, () => { + console.log(`Listening on ${hostname}:${port}`); startMonitors(); });