Skip to content

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

@ultravires

Description

@ultravires

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions