-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { | ||
createProxyMiddleware | ||
} = require('http-proxy-middleware') | ||
|
||
module.exports = (req, res) => { | ||
let target = '' | ||
let headers= {} | ||
// 代理目标地址 | ||
if (req.url.startsWith('/mjapi')) { //这里使用/api可能会与vercel serverless 的 api 路径冲突,根据接口进行调整 | ||
target = process.env.MJ_SERVER; | ||
headers= { | ||
'Mj-Api-Secret': process.env.MJ_API_SECRET // 添加自定义请求头 | ||
} | ||
} | ||
// 创建代理对象并转发请求 | ||
createProxyMiddleware({ | ||
target, | ||
changeOrigin: true, | ||
headers, | ||
pathRewrite: { | ||
// 通过路径重写,去除请求路径中的 `/api` | ||
'^/mjapi/': '/' | ||
} | ||
})(req, res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"rewrites": [ | ||
{ | ||
"source": "/openapi/(.*)", | ||
"destination": "/api/proxy" | ||
}, | ||
{ | ||
"source": "/mjapi/(.*)", | ||
"destination": "/api/proxy" | ||
} | ||
] | ||
} |