From 5f1415d9d4f96fa8051698a267f47a1189bc2df3 Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 24 Nov 2023 17:14:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=8E=E7=AB=AF=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=20`host`=20=E5=92=8C=20`port`.=20?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=20`SUB=5FSTORE=5FBACKEND?= =?UTF-8?q?=5FAPI=5FHOST`=20=E9=BB=98=E8=AE=A4=20`::`,=20`SUB=5FSTORE=5FBA?= =?UTF-8?q?CKEND=5FAPI=5FPORT`=20=E9=BB=98=E8=AE=A4=20`3000`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/index.js | 9 +++++++-- backend/src/vendor/express.js | 8 +++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/package.json b/backend/package.json index a642bd3..56e2762 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.99", + "version": "2.14.101", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/restful/index.js b/backend/src/restful/index.js index 8c2f7b5..f8f220c 100644 --- a/backend/src/restful/index.js +++ b/backend/src/restful/index.js @@ -15,8 +15,13 @@ import registerMiscRoutes from './miscs'; import registerNodeInfoRoutes from './node-info'; export default function serve() { - const $app = express({ substore: $ }); - + let port; + let host; + if ($.env.isNode) { + port = eval('process.env.SUB_STORE_BACKEND_API_PORT'); + host = eval('process.env.SUB_STORE_BACKEND_API_HOST'); + } + const $app = express({ substore: $, port, host }); // register routes registerCollectionRoutes($app); registerSubscriptionRoutes($app); diff --git a/backend/src/vendor/express.js b/backend/src/vendor/express.js index 61b9343..e3eb5ef 100644 --- a/backend/src/vendor/express.js +++ b/backend/src/vendor/express.js @@ -1,8 +1,9 @@ /* eslint-disable no-undef */ import { ENV } from './open-api'; -export default function express({ substore: $, port }) { +export default function express({ substore: $, port, host }) { port = port || 3000; + host = host || '::'; const { isNode } = ENV(); const DEFAULT_HEADERS = { 'Content-Type': 'text/plain;charset=UTF-8', @@ -29,8 +30,9 @@ export default function express({ substore: $, port }) { // adapter app.start = () => { - app.listen(port, () => { - $.info(`Express started on port: ${port}`); + const listener = app.listen(port, host, () => { + const { address, port } = listener.address(); + $.info(`Express started on ${address}:${port}`); }); }; return app;