mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-22 03:59:06 +08:00
feat: Node 版后端支持挂载前端文件夹, 环境变量 SUB_STORE_FRONTEND_PATH
, SUB_STORE_FRONTEND_HOST
, SUB_STORE_FRONTEND_PORT
This commit is contained in:
parent
7aaa03d4ca
commit
7a793b954e
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.14.118",
|
||||
"version": "2.14.119",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
@ -16,6 +16,7 @@
|
||||
"dependencies": {
|
||||
"automerge": "1.0.1-preview.7",
|
||||
"body-parser": "^1.19.0",
|
||||
"connect-history-api-fallback": "^2.0.0",
|
||||
"express": "^4.17.1",
|
||||
"js-base64": "^3.7.2",
|
||||
"lodash": "^4.17.21",
|
||||
|
10
backend/pnpm-lock.yaml
generated
10
backend/pnpm-lock.yaml
generated
@ -11,6 +11,9 @@ dependencies:
|
||||
body-parser:
|
||||
specifier: ^1.19.0
|
||||
version: registry.npmmirror.com/body-parser@1.19.0
|
||||
connect-history-api-fallback:
|
||||
specifier: ^2.0.0
|
||||
version: registry.npmmirror.com/connect-history-api-fallback@2.0.0
|
||||
express:
|
||||
specifier: ^4.17.1
|
||||
version: registry.npmmirror.com/express@4.17.1
|
||||
@ -3543,6 +3546,13 @@ packages:
|
||||
xdg-basedir: registry.npmmirror.com/xdg-basedir@4.0.0
|
||||
dev: true
|
||||
|
||||
registry.npmmirror.com/connect-history-api-fallback@2.0.0:
|
||||
resolution: {integrity: sha512-U73+6lQFmfiNPrYbXqr6kZ1i1wiRqXnp2nhMsINseWXO8lDau0LGEffJ8kQi4EjLZympVgRdvqjAgiZ1tgzDDA==, registry: http://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/connect-history-api-fallback/-/connect-history-api-fallback-2.0.0.tgz}
|
||||
name: connect-history-api-fallback
|
||||
version: 2.0.0
|
||||
engines: {node: '>=0.8'}
|
||||
dev: false
|
||||
|
||||
registry.npmmirror.com/console-browserify@1.2.0:
|
||||
resolution: {integrity: sha512-ZMkYO/LkF17QvCPqM0gxw8yUzigAOZOSWSHg91FH6orS7vcEj5dVZTidN2fQ14yBSdg97RqhSNwLUXInd52OTA==, registry: http://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/console-browserify/-/console-browserify-1.2.0.tgz}
|
||||
name: console-browserify
|
||||
|
@ -37,4 +37,46 @@ export default function serve() {
|
||||
registerMiscRoutes($app);
|
||||
|
||||
$app.start();
|
||||
|
||||
if ($.env.isNode) {
|
||||
const path = eval(`require("path")`);
|
||||
const fs = eval(`require("fs")`);
|
||||
const fe_port = eval('process.env.SUB_STORE_FRONTEND_PORT') || 3001;
|
||||
const fe_host =
|
||||
eval('process.env.SUB_STORE_FRONTEND_HOST') || host || '::';
|
||||
const fe_path = eval('process.env.SUB_STORE_FRONTEND_PATH');
|
||||
const fe_abs_path = path.resolve(
|
||||
fe_path || path.join(__dirname, 'frontend'),
|
||||
);
|
||||
if (fe_path) {
|
||||
try {
|
||||
fs.accessSync(path.join(fe_abs_path, 'index.html'));
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
`[FRONTEND] index.html file not found in ${fe_abs_path}`,
|
||||
);
|
||||
}
|
||||
|
||||
const express_ = eval(`require("express")`);
|
||||
const history = eval(`require("connect-history-api-fallback")`);
|
||||
|
||||
const app = express_();
|
||||
|
||||
const staticFileMiddleware = express_.static(fe_path);
|
||||
|
||||
app.use(staticFileMiddleware);
|
||||
app.use(
|
||||
history({
|
||||
disableDotRule: true,
|
||||
verbose: true,
|
||||
}),
|
||||
);
|
||||
app.use(staticFileMiddleware);
|
||||
|
||||
const listener = app.listen(fe_port, fe_host, () => {
|
||||
const { address, port } = listener.address();
|
||||
$.info(`[FRONTEND] ${address}:${port}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
backend/src/vendor/express.js
vendored
2
backend/src/vendor/express.js
vendored
@ -32,7 +32,7 @@ export default function express({ substore: $, port, host }) {
|
||||
app.start = () => {
|
||||
const listener = app.listen(port, host, () => {
|
||||
const { address, port } = listener.address();
|
||||
$.info(`Express started on ${address}:${port}`);
|
||||
$.info(`[BACKEND] ${address}:${port}`);
|
||||
});
|
||||
};
|
||||
return app;
|
||||
|
5
package.json
Normal file
5
package.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"connect-history-api-fallback": "^2.0.0"
|
||||
}
|
||||
}
|
19
pnpm-lock.yaml
generated
Normal file
19
pnpm-lock.yaml
generated
Normal file
@ -0,0 +1,19 @@
|
||||
lockfileVersion: '6.0'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
dependencies:
|
||||
connect-history-api-fallback:
|
||||
specifier: ^2.0.0
|
||||
version: registry.npmmirror.com/connect-history-api-fallback@2.0.0
|
||||
|
||||
packages:
|
||||
|
||||
registry.npmmirror.com/connect-history-api-fallback@2.0.0:
|
||||
resolution: {integrity: sha512-U73+6lQFmfiNPrYbXqr6kZ1i1wiRqXnp2nhMsINseWXO8lDau0LGEffJ8kQi4EjLZympVgRdvqjAgiZ1tgzDDA==, registry: http://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/connect-history-api-fallback/-/connect-history-api-fallback-2.0.0.tgz}
|
||||
name: connect-history-api-fallback
|
||||
version: 2.0.0
|
||||
engines: {node: '>=0.8'}
|
||||
dev: false
|
Loading…
x
Reference in New Issue
Block a user