http-proxy-middleware 能不能把 post 请求重定向成 get 请求

2017-12-20 10:09:30 +08:00
 nuxt
第三方系统会像我前台的页面 post 一个请求,我没法处理,因为没有服务端,线上可以用 nginx 转发,但是开发环境只能自己配置 webpack-dev-server 了
3897 次点击
所在节点    程序员
6 条回复
lairdnote
2017-12-20 10:14:40 +08:00
自己写一个 post 的接口 转 get 就 ok 了。。代理一下
nuxt
2017-12-20 10:20:52 +08:00
@lairdnote 利用现有的来实现,不想把开发环境弄得太复杂
loy6491
2017-12-20 14:09:32 +08:00
onProxyReq: function(reqProxy, req, res) {
reqProxy.method = 'GET';
}
SourceMan
2017-12-20 14:23:18 +08:00
如三楼所说,request 拦截器拦下了修改 method 再 return 回去发请求。
nuxt
2017-12-20 18:18:06 +08:00
@loy6491 谢了 我试试 我现在还是用 php 帮助转发了下 在 github 问了也没人回答
nuxt
2017-12-20 18:26:16 +08:00
@SourceMan 具体怎么写

```
proxyTable: {
'/withDrawals': {
filter: function (path, req) {
return req.method === 'POST'
},
onProxyReq: function(reqProxy, req, res) {
reqProxy.method = 'GET'
return reqProxy
},
target: '/withDrawals'
},
'/rechargeMoney': {
filter: function (path, req) {
return req.method === 'POST'
},
onProxyReq: function(reqProxy, req, res) {
reqProxy.method = 'GET'
return reqProxy
},
target: '/rechargeMoney'
}
},
```

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/416183

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX