• 请不要在回答技术问题时复制粘贴 AI 生成的内容
nuxt
V2EX  ›  程序员

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

  •  
  •   nuxt · Dec 20, 2017 · 4511 views
    This topic created in 3075 days ago, the information mentioned may be changed or developed.
    第三方系统会像我前台的页面 post 一个请求,我没法处理,因为没有服务端,线上可以用 nginx 转发,但是开发环境只能自己配置 webpack-dev-server 了
    6 replies    2017-12-20 18:26:16 +08:00
    lairdnote
        1
    lairdnote  
       Dec 20, 2017
    自己写一个 post 的接口 转 get 就 ok 了。。代理一下
    nuxt
        2
    nuxt  
    OP
       Dec 20, 2017
    @lairdnote 利用现有的来实现,不想把开发环境弄得太复杂
    loy6491
        3
    loy6491  
       Dec 20, 2017   ❤️ 1
    onProxyReq: function(reqProxy, req, res) {
    reqProxy.method = 'GET';
    }
    SourceMan
        4
    SourceMan  
       Dec 20, 2017
    如三楼所说,request 拦截器拦下了修改 method 再 return 回去发请求。
    nuxt
        5
    nuxt  
    OP
       Dec 20, 2017
    @loy6491 谢了 我试试 我现在还是用 php 帮助转发了下 在 github 问了也没人回答
    nuxt
        6
    nuxt  
    OP
       Dec 20, 2017
    @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'
    }
    },
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   925 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 20:01 · PVG 04:01 · LAX 13:01 · JFK 16:01
    ♥ Do have faith in what you're doing.