mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-06-04 11:13:59 +08:00
Perf: 提前加载 .env;后端复用前端 Path
This commit is contained in:
parent
bb5c9d43d0
commit
dd92a26e6c
@ -11,6 +11,7 @@
|
|||||||
* @documentation: https://www.notion.so/Sub-Store-6259586994d34c11a4ced5c406264b46
|
* @documentation: https://www.notion.so/Sub-Store-6259586994d34c11a4ced5c406264b46
|
||||||
*/
|
*/
|
||||||
import { version } from '../package.json';
|
import { version } from '../package.json';
|
||||||
|
import $ from '@/core/app';
|
||||||
console.log(
|
console.log(
|
||||||
`
|
`
|
||||||
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
|
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
|
||||||
@ -18,7 +19,10 @@ console.log(
|
|||||||
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
|
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
|
||||||
`,
|
`,
|
||||||
);
|
);
|
||||||
|
if ($.env.isNode) {
|
||||||
|
const dotenv = eval(`require("dotenv")`);
|
||||||
|
dotenv.config();
|
||||||
|
}
|
||||||
import migrate from '@/utils/migration';
|
import migrate from '@/utils/migration';
|
||||||
import serve from '@/restful';
|
import serve from '@/restful';
|
||||||
|
|
||||||
|
@ -24,22 +24,23 @@ import registerParserRoutes from './parser';
|
|||||||
export default function serve() {
|
export default function serve() {
|
||||||
let port;
|
let port;
|
||||||
let host;
|
let host;
|
||||||
let prefix;
|
|
||||||
if ($.env.isNode) {
|
if ($.env.isNode) {
|
||||||
const dotenv = eval(`require("dotenv")`);
|
|
||||||
dotenv.config();
|
|
||||||
port = eval('process.env.SUB_STORE_BACKEND_API_PORT') || 3000;
|
port = eval('process.env.SUB_STORE_BACKEND_API_PORT') || 3000;
|
||||||
host = eval('process.env.SUB_STORE_BACKEND_API_HOST') || '::';
|
host = eval('process.env.SUB_STORE_BACKEND_API_HOST') || '::';
|
||||||
prefix = eval('process.env.SUB_STORE_BACKEND_PATH_PREFIX');
|
|
||||||
if (prefix && !prefix.startsWith("/")){
|
|
||||||
prefix = '/${prefix}'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const $app = express({ substore: $, port, host });
|
const $app = express({ substore: $, port, host });
|
||||||
if (prefix && prefix.length >= 2){
|
if ($.env.isNode) {
|
||||||
|
const be_prefix = eval('process.env.SUB_STORE_BACKEND_PREFIX');
|
||||||
|
const fe_be_path = eval('process.env.SUB_STORE_FRONTEND_BACKEND_PATH');
|
||||||
|
if (be_prefix) {
|
||||||
|
if(!fe_be_path.startsWith('/')){
|
||||||
|
throw new Error(
|
||||||
|
'SUB_STORE_FRONTEND_BACKEND_PATH should start with /',
|
||||||
|
);
|
||||||
|
}
|
||||||
$app.use((req, res, next) => {
|
$app.use((req, res, next) => {
|
||||||
if (req.path.startsWith(prefix)) {
|
if (req.path.startsWith(fe_be_path)) {
|
||||||
const newPath = req.url.replace(prefix, '') || '/';
|
const newPath = req.url.replace(fe_be_path, '') || '/';
|
||||||
req.url = newPath;
|
req.url = newPath;
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
@ -47,7 +48,7 @@ export default function serve() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// register routes
|
// register routes
|
||||||
registerCollectionRoutes($app);
|
registerCollectionRoutes($app);
|
||||||
registerSubscriptionRoutes($app);
|
registerSubscriptionRoutes($app);
|
||||||
@ -219,6 +220,7 @@ export default function serve() {
|
|||||||
let be_download_rewrite = '';
|
let be_download_rewrite = '';
|
||||||
let be_api_rewrite = '';
|
let be_api_rewrite = '';
|
||||||
let be_share_rewrite = `${be_share}:type/:name`;
|
let be_share_rewrite = `${be_share}:type/:name`;
|
||||||
|
let prefix = eval('process.env.SUB_STORE_BACKEND_PREFIX') ? fe_be_path : '';
|
||||||
if (fe_be_path) {
|
if (fe_be_path) {
|
||||||
if (!fe_be_path.startsWith('/')) {
|
if (!fe_be_path.startsWith('/')) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user