添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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
  • Yes, this behavior used to work in the previous version
  • The previous version in which this bug was not present was

    works fine with the webpack-builder

    Description

    When using bypass in the proxy config, no (proxy) target should be needed. However, if no target is specified, the viteProxyMiddleware reports an error on the command line. Besides this, everything works as expected. However, such an unnecessary error is very confusing and distracts from other console outputs.

    Also, the webpack-based dev-server does not show such an error.

    Minimal Reproduction

    Assume this proxy-config in a file proxy.mjs :

    export default {
      '/': {
        "bypass": function (req, res, proxyOptions) {
          if (req.url === '/ping') {
            res.setHeader('Content-Type', "text/plain");
            res.end("pong");
            return true;
          else {
            return req.url;
    

    There is no need for a target. In such cases, there might not even be a target.

    Starting ng serve --proxy-config proxy.mjs with the webpack-based dev-server works fine. When starting it with the esbuild-based dev-server an exception occurs on the command line:

    [vite] http proxy error: Must provide a proper URL as target
    

    Exception or Error

    Error: Must provide a proper URL as target
        at ProxyServer.<anonymous> (file:///C:/temp/ping/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:63692:36)
        at viteProxyMiddleware (file:///C:/temp/ping/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:64005:23)
        at call (file:///C:/temp/ping/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:50559:7)
        at next (file:///C:/temp/ping/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:50503:5)
        at cors (file:///C:/temp/ping/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:51031:7)
        at file:///C:/temp/ping/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:51067:17
        at originCallback (file:///C:/temp/ping/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:51057:15)
        at file:///C:/temp/ping/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:51062:13
        at optionsCallback (file:///C:/temp/ping/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:51042:9)
        at corsMiddleware (file:///C:/temp/ping/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:51047:7)
    

    Your Environment

    Angular CLI: 16.2.9
    Node: 20.9.0 (Unsupported)
    Package Manager: npm 10.1.0
    OS: win32 x64
    Angular: 16.2.11
    ... animations, common, compiler, compiler-cli, core, forms
    ... platform-browser, platform-browser-dynamic, router
    Package                         Version
    ---------------------------------------------------------
    @angular-devkit/architect       0.1602.9
    @angular-devkit/build-angular   16.2.9
    @angular-devkit/core            16.2.9
    @angular-devkit/schematics      16.2.9
    @angular/cli                    16.2.9
    @schematics/angular             16.2.9
    rxjs                            7.8.1
    typescript                      5.1.6
    zone.js                         0.13.3
    

    Anything else relevant?

    I've seen the same behavior in the current RC of Angular 17.

    This is work as webpack-dev-server specific implementation for bypass. https://github.com/webpack/webpack-dev-server/blob/master/lib/Server.js#L2234

    The proxy library that is used by both vite and webpack-dev-server always requires a target including when using bypass.

    As mentioned, the bypass method is a Webpack extension to the underlying proxy package. While Vite does provide some support for this, it does not support the use of a true return value. Returning a string url replacement or false appears to be implemented but all other values result in the underlying proxy package being used.
    Resolving this would most likely require a feature request for Vite itself to handle the return true case.

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.