-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
75 lines (70 loc) · 2.23 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const express = require("express");
const { createProxyMiddleware } = require("http-proxy-middleware");
const app = express();
const port = 3000;
app.use(
"/anthropic",
createProxyMiddleware({
target: "https://api.anthropic.com",
pathRewrite: {
"^/anthropic": "", // 将路径中的 /anthropic 替换为空字符串
},
changeOrigin: true,
onProxyReq: (proxyReq, req, res) => {
// 移除 'x-forwarded-for' 和 'x-real-ip' 头,以确保不传递原始客户端 IP 地址等信息
proxyReq.removeHeader("x-forwarded-for");
proxyReq.removeHeader("x-real-ip");
},
onProxyRes: function (proxyRes, req, res) {
proxyRes.headers["Access-Control-Allow-Origin"] = "*";
},
})
);
app.use(
"/arxiv/api",
createProxyMiddleware({
target: "http://export.arxiv.org/api/query",
changeOrigin: true,
onProxyReq: (proxyReq, req, res) => {
// 移除 'x-forwarded-for' 和 'x-real-ip' 头,以确保不传递原始客户端 IP 地址等信息
proxyReq.removeHeader("x-forwarded-for");
proxyReq.removeHeader("x-real-ip");
},
onProxyRes: function (proxyRes, req, res) {
proxyRes.headers["Access-Control-Allow-Origin"] = "*";
},
})
);
app.use(
"/pdf",
createProxyMiddleware({
target: "https://arxiv.org",
changeOrigin: true,
onProxyReq: (proxyReq, req, res) => {
// 移除 'x-forwarded-for' 和 'x-real-ip' 头,以确保不传递原始客户端 IP 地址等信息
proxyReq.removeHeader("x-forwarded-for");
proxyReq.removeHeader("x-real-ip");
},
onProxyRes: function (proxyRes, req, res) {
proxyRes.headers["Access-Control-Allow-Origin"] = "*";
},
})
);
app.use(
"/",
createProxyMiddleware({
target: "https://api.openai.com",
changeOrigin: true,
onProxyReq: (proxyReq, req, res) => {
// 移除 'x-forwarded-for' 和 'x-real-ip' 头,以确保不传递原始客户端 IP 地址等信息
proxyReq.removeHeader("x-forwarded-for");
proxyReq.removeHeader("x-real-ip");
},
onProxyRes: function (proxyRes, req, res) {
proxyRes.headers["Access-Control-Allow-Origin"] = "*";
},
})
);
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});