Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: http-proxy 转发时 支持 axios的所有参数 #2565

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/http-proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ export const httpProxy = {
host: 'http://127.0.0.1',
match: /\/assets\/(.*)/,
target: 'http://127.0.0.1/$1',

//额外的axios请求config, 会照搬过去
extReqOptions:{
//用来设置不校验https的ssl
httpsAgent: new https.Agent({ rejectUnauthorized: false })
}
}
```
2 changes: 2 additions & 0 deletions packages/http-proxy/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export interface HttpProxyStrategy {
ignoreHeaders?: {
[key: string]: boolean;
}
// 额外的axios请求config, 详情见 https://axios-http.com/docs/req_config
extReqOptions?: { [key: string]: any }
}

export interface HttpProxyConfig extends HttpProxyStrategy {
Expand Down
1 change: 1 addition & 0 deletions packages/http-proxy/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class HttpProxyMiddleware implements IMiddleware<any, any> {
const isStream = targetRes.on && targetRes.writable;

const reqOptions: any = {
...(this.httpProxy.extReqOptions || {}),
method,
url: url.href,
headers: reqHeaders,
Expand Down