V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
nuxt
V2EX  ›  程序员

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

  •  
  •   nuxt · 2017-12-20 10:09:30 +08:00 · 3859 次点击
    这是一个创建于 2312 天前的主题,其中的信息可能已经有所发展或是发生改变。
    第三方系统会像我前台的页面 post 一个请求,我没法处理,因为没有服务端,线上可以用 nginx 转发,但是开发环境只能自己配置 webpack-dev-server 了
    6 条回复    2017-12-20 18:26:16 +08:00
    lairdnote
        1
    lairdnote  
       2017-12-20 10:14:40 +08:00
    自己写一个 post 的接口 转 get 就 ok 了。。代理一下
    nuxt
        2
    nuxt  
    OP
       2017-12-20 10:20:52 +08:00
    @lairdnote 利用现有的来实现,不想把开发环境弄得太复杂
    loy6491
        3
    loy6491  
       2017-12-20 14:09:32 +08:00   ❤️ 1
    onProxyReq: function(reqProxy, req, res) {
    reqProxy.method = 'GET';
    }
    SourceMan
        4
    SourceMan  
       2017-12-20 14:23:18 +08:00
    如三楼所说,request 拦截器拦下了修改 method 再 return 回去发请求。
    nuxt
        5
    nuxt  
    OP
       2017-12-20 18:18:06 +08:00
    @loy6491 谢了 我试试 我现在还是用 php 帮助转发了下 在 github 问了也没人回答
    nuxt
        6
    nuxt  
    OP
       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'
    }
    },
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5477 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 03:11 · PVG 11:11 · LAX 20:11 · JFK 23:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.