首页 > 解决方案 > 使用 http-proxy-middleware 从请求中删除标头

问题描述

我正在尝试使用 http-proxy-middleware 从特定请求中删除响应标头。我正在使用onProxyRes类似的方法:

onProxyRes: (proxyRes, req, res) => {
  if(req.path.endsWith('api/endpoint') {
    delete proxyRes.headers['set-cookie'];
    
    // this just to test
    res.setHeader('X-proxy-header-changed', 'true');
  }
}

这似乎正常工作,但在某些情况下,当调用未授权并且网关发回我的 CSP 阻止的重定向时,这不起作用并且无论如何设置了 cookie。我有一种感觉,我对这应该如何工作的理解是有缺陷的。该调用不会返回onProxyRes回调吗?如果是这样,有没有更好的方法来做到这一点?谢谢。

标签: javascriptnode.jsexpresshttp-proxy-middleware

解决方案


推荐阅读