Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: onProxyReq: function(proxyReq, req, res) res.redirect is not a function #3924

Closed
ultravires opened this issue Nov 8, 2024 · 1 comment · Fixed by #3936
Closed
Labels
bug Something isn't working

Comments

@ultravires
Copy link

Version

System:
OS: Windows 11 10.0.22631
CPU: (32) x64 AMD Ryzen 9 7945HX with Radeon Graphics
Memory: 2.00 GB / 15.69 GB
Browsers:
Edge: Chromium (127.0.2651.105)
Internet Explorer: 11.0.22621.3527
npmPackages:
@rsbuild/core: 1.0.18 => 1.0.18
@rsbuild/plugin-vue2: ^1.0.1 => 1.0.1

Details

      '/a.path/': {
        target: process.env.VUE_APP_BASE_URL,
        changeOrigin: true,
        onProxyReq: function (proxyReq, req, res) {
          res.redirect(`https://some.xx.com${req._parsedUrl.path}`);
          return true;
        },
      },
TypeError: res.redirect is not a function
    at ProxyServer.onProxyReq (D:/Workspaces/WebProjects/leadal/cis-workspace/rsbuild.config.mjs:179:15)
    at ProxyServer.emit (D:\Workspaces\WebProjects\leadal\cis-workspace\node_modules\.pnpm\@rsbuild+core@1.0.18\node_modules\@rsbuild\core\compiled\http-proxy-middleware\index.js:705:35)
    at ClientRequest.<anonymous> (D:\Workspaces\WebProjects\leadal\cis-workspace\node_modules\.pnpm\@rsbuild+core@1.0.18\node_modules\@rsbuild\core\compiled\http-proxy-middleware\index.js:2709:22)
    at ClientRequest.emit (node:events:519:28)
    at tickOnSocket (node:_http_client:843:7)
    at onSocketNT (node:_http_client:906:5)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

Node.js v20.18.0
 ELIFECYCLE  Command failed with exit code 1.

Reproduce link

https://codesandbox.io/p/github/rspack-contrib/rsbuild-codesandbox-example/main

Reproduce Steps

  1. pnpm i pnpm dev
  2. check the logs
@ultravires ultravires added the bug Something isn't working label Nov 8, 2024
@9aoy
Copy link
Contributor

9aoy commented Nov 8, 2024

The res type of http-proxy-middleware refers to express and res.redirect is express only, but express is not actually used in rsbuild.
This is a known issue of http-proxy-middleware v2 and is fixed in v3. Since http-proxy-middleware v2 to v3 has some breaking changes for users, we will think about how to handle it in rsbuild.

chimurai/http-proxy-middleware#730

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants