feat: 后端支持自定义 hostport. 环境变量 SUB_STORE_BACKEND_API_HOST 默认 ::, SUB_STORE_BACKEND_API_PORT 默认 3000

This commit is contained in:
xream 2023-11-24 17:14:21 +08:00
parent 1e3b4a147a
commit 5f1415d9d4
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
3 changed files with 13 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "sub-store", "name": "sub-store",
"version": "2.14.99", "version": "2.14.101",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js", "main": "src/main.js",
"scripts": { "scripts": {

View File

@ -15,8 +15,13 @@ import registerMiscRoutes from './miscs';
import registerNodeInfoRoutes from './node-info'; import registerNodeInfoRoutes from './node-info';
export default function serve() { 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 // register routes
registerCollectionRoutes($app); registerCollectionRoutes($app);
registerSubscriptionRoutes($app); registerSubscriptionRoutes($app);

View File

@ -1,8 +1,9 @@
/* eslint-disable no-undef */ /* eslint-disable no-undef */
import { ENV } from './open-api'; import { ENV } from './open-api';
export default function express({ substore: $, port }) { export default function express({ substore: $, port, host }) {
port = port || 3000; port = port || 3000;
host = host || '::';
const { isNode } = ENV(); const { isNode } = ENV();
const DEFAULT_HEADERS = { const DEFAULT_HEADERS = {
'Content-Type': 'text/plain;charset=UTF-8', 'Content-Type': 'text/plain;charset=UTF-8',
@ -29,8 +30,9 @@ export default function express({ substore: $, port }) {
// adapter // adapter
app.start = () => { app.start = () => {
app.listen(port, () => { const listener = app.listen(port, host, () => {
$.info(`Express started on port: ${port}`); const { address, port } = listener.address();
$.info(`Express started on ${address}:${port}`);
}); });
}; };
return app; return app;