mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-04-19 12:19:33 +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
|
||||
*/
|
||||
import { version } from '../package.json';
|
||||
import $ from '@/core/app';
|
||||
console.log(
|
||||
`
|
||||
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
|
||||
@ -18,7 +19,10 @@ console.log(
|
||||
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
|
||||
`,
|
||||
);
|
||||
|
||||
if ($.env.isNode) {
|
||||
const dotenv = eval(`require("dotenv")`);
|
||||
dotenv.config();
|
||||
}
|
||||
import migrate from '@/utils/migration';
|
||||
import serve from '@/restful';
|
||||
|
||||
|
@ -24,22 +24,23 @@ import registerParserRoutes from './parser';
|
||||
export default function serve() {
|
||||
let port;
|
||||
let host;
|
||||
let prefix;
|
||||
if ($.env.isNode) {
|
||||
const dotenv = eval(`require("dotenv")`);
|
||||
dotenv.config();
|
||||
port = eval('process.env.SUB_STORE_BACKEND_API_PORT') || 3000;
|
||||
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 });
|
||||
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) => {
|
||||
if (req.path.startsWith(prefix)) {
|
||||
const newPath = req.url.replace(prefix, '') || '/';
|
||||
if (req.path.startsWith(fe_be_path)) {
|
||||
const newPath = req.url.replace(fe_be_path, '') || '/';
|
||||
req.url = newPath;
|
||||
next();
|
||||
} else {
|
||||
@ -47,7 +48,7 @@ export default function serve() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
// register routes
|
||||
registerCollectionRoutes($app);
|
||||
registerSubscriptionRoutes($app);
|
||||
@ -219,6 +220,7 @@ export default function serve() {
|
||||
let be_download_rewrite = '';
|
||||
let be_api_rewrite = '';
|
||||
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.startsWith('/')) {
|
||||
throw new Error(
|
||||
|
Loading…
x
Reference in New Issue
Block a user