Files
ThinkFlowAI/proxy-server.js
史悦 199dd8a9db refactor(部署): 重构部署架构,使用本地代理服务器替代环境变量配置
- 删除 Dockerfile.dev 和 entrypoint.sh,简化开发环境配置
- 修改 Dockerfile 使用 node 基础镜像并添加代理服务器
- 新增 proxy-server.js 处理 API 请求代理
- 更新 nginx 配置指向本地代理服务
- 修改前端请求添加自定义 base URL 头支持
2026-01-22 16:40:16 +08:00

46 lines
1.2 KiB
JavaScript

const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const cors = require('cors');
const app = express();
const PORT = process.env.PROXY_PORT || 3000;
app.use(cors());
app.use(express.json());
app.use('/api/chat', createProxyMiddleware({
target: 'https://thinkflow.lz-t.top',
changeOrigin: true,
pathRewrite: {
'^/api/chat': '/chat/completions'
},
onProxyReq: (proxyReq, req, res) => {
const customBaseUrl = req.headers['x-custom-base-url'];
if (customBaseUrl) {
const url = new URL(customBaseUrl);
proxyReq.path = url.pathname;
proxyReq.setHeader('Host', url.host);
}
}
}));
app.use('/api/image', createProxyMiddleware({
target: 'https://thinkflow.lz-t.top',
changeOrigin: true,
pathRewrite: {
'^/api/image': '/images/generations'
},
onProxyReq: (proxyReq, req, res) => {
const customBaseUrl = req.headers['x-custom-base-url'];
if (customBaseUrl) {
const url = new URL(customBaseUrl);
proxyReq.path = url.pathname;
proxyReq.setHeader('Host', url.host);
}
}
}));
app.listen(PORT, () => {
console.log(`Proxy server running on port ${PORT}`);
});