mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2026-05-05 15:58:03 +08:00
feat: Node.js 前端代理后端路由
This commit is contained in:
@@ -18,8 +18,8 @@ export default function serve() {
|
||||
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');
|
||||
port = eval('process.env.SUB_STORE_BACKEND_API_PORT') || 3000;
|
||||
host = eval('process.env.SUB_STORE_BACKEND_API_HOST') || '::';
|
||||
}
|
||||
const $app = express({ substore: $, port, host });
|
||||
// register routes
|
||||
@@ -59,11 +59,15 @@ export default function serve() {
|
||||
|
||||
const express_ = eval(`require("express")`);
|
||||
const history = eval(`require("connect-history-api-fallback")`);
|
||||
const { createProxyMiddleware } = eval(
|
||||
`require("http-proxy-middleware")`,
|
||||
);
|
||||
|
||||
const app = express_();
|
||||
|
||||
const staticFileMiddleware = express_.static(fe_path);
|
||||
|
||||
app.use('/api', createProxyMiddleware(`http://127.0.0.1:${port}`));
|
||||
app.use(staticFileMiddleware);
|
||||
app.use(
|
||||
history({
|
||||
|
||||
2
backend/src/vendor/express.js
vendored
2
backend/src/vendor/express.js
vendored
@@ -2,8 +2,6 @@
|
||||
import { ENV } from './open-api';
|
||||
|
||||
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',
|
||||
|
||||
Reference in New Issue
Block a user