修复 public 服务转发

This commit is contained in:
whyour
2023-05-10 01:07:46 +08:00
parent 7c3bb90d12
commit 50718ba714
7 changed files with 2790 additions and 2387 deletions
+10
View File
@@ -15,12 +15,22 @@ import * as Sentry from '@sentry/node';
import { EnvModel } from '../data/env';
import { errors } from 'celebrate';
import path from 'path';
import { createProxyMiddleware } from 'http-proxy-middleware';
export default ({ app }: { app: Application }) => {
app.enable('trust proxy');
app.use(cors());
app.use(`${config.api.prefix}/static`, express.static(config.uploadPath));
app.use(
'/api/public',
createProxyMiddleware({
target: `http://localhost:${config.publicPort}/api`,
changeOrigin: true,
pathRewrite: { '/api/public': '' },
}),
);
app.use((req, res, next) => {
if (req.path.startsWith('/api') || req.path.startsWith('/open')) {
next();