【问题标题】:webpack devServer proxy doesn't catch my requestwebpack devServer 代理没有捕捉到我的请求
【发布时间】:2023-01-30 05:30:55
【问题描述】:

我在 http://localhost:8050/ 上有一个 UI 应用程序,在 http://foo.local.bar.com 上有一个 api 服务器。 我直接登录到服务器,但是当我获取 GET 方法 http://foo.local.bar.com/myapi/api/goo/maa 时,我也需要 UI 将 cookie 发送到服务器。 在我的配置 json 中,我添加了 devServer 和代理,但它似乎不起作用:

 devServer: {
    proxy: {
      '/api/*': {
        "target": "http://foo.local.bar.com",
        logLevel: 'debug',
        secure: false,
        changeOrigin: true,
        withCredentials: true,
        cookieDomainRewrite: "localhost",
        onProxyReq: proxyReq => {
          console.log("onProxyReq 1 !!!!!!!!") // I don't see any console logs, so I also think the proxy doesn't "catch" my request...
          proxyReq.setHeader("Cookie", ".MYCOOKIE=123445"); 
          console.log("onProxyReq 2 !!!!!!!!", proxyReq)
        }
      }
    }
  },

但我仍然收到“此请求的授权已被拒绝”。 401 错误。

有任何想法吗?我试过了,就像,一切...

【问题讨论】:

    标签: node.js webpack-dev-server


    【解决方案1】:

    这最终帮助了我:

    proxy: {
          '/myapi/api/*': { // changed the url
            target: 'http://foo.local.bar.com/', 
            headers: {
              Cookie: "MYCOOKIE=123445" // moved cookie to here
            },
            logLevel: 'debug',
            secure: false,
            changeOrigin: true,
            withCredentials: true,
          }
        },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-15
      • 2015-11-21
      • 1970-01-01
      • 2016-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多