HMR gets 404 on .hot-update.json #507

Closed
opened 2025-08-09 17:16:33 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @offbeatful on 8/15/2017

Version: 2.0.0

When webpack configuration has publicPath = "/" (build everything to root) ConditionalProxyMiddleware fails to proxy requests to webpack-dev-server. In my case all requests to root (like http://localhost:5000/7d8b1be5454ed9e44b78.hot-update.json) fails with 404.

It was working fine for preview2 but does not work for new bits.

After reviewing/debugging your code I found that the following lines were added to ConditionalProxyMiddleware.cs:

             if (!pathPrefix.StartsWith("/"))
             {
                 pathPrefix = "/" + pathPrefix;
             }

then it actually fails when performing a check:

        public async Task Invoke(HttpContext context)
        {
            if (context.Request.Path.StartsWithSegments(_pathPrefix))
            {
                var didProxyRequest = await PerformProxyRequest(context);
                if (didProxyRequest)
                {
                    return;
                }
            }
...

Here if _pathPrefix is "/" and context.Request.Path = "/7d8b1be5454ed9e44b78.hot-update.json" then StartsWithSegments will return false.

Interesting that pathPrefix in ctor is actually an empty string (passed from WebpackDevMiddleware). That is why it was working for previous (preview2) version.

The fix would be to skip inserting slash in case pathPrefix is an empty string. Or change the code of actual check in Invoke method.

Please let me know if you want me to submit a pull request.

*Originally created by @offbeatful on 8/15/2017* Version: 2.0.0 When webpack configuration has publicPath = "/" (build everything to root) ConditionalProxyMiddleware fails to proxy requests to webpack-dev-server. In my case all requests to root (like http://localhost:5000/7d8b1be5454ed9e44b78.hot-update.json) fails with 404. It was working fine for preview2 but does not work for new bits. After reviewing/debugging your code I found that the following lines were added to ConditionalProxyMiddleware.cs: ```cs if (!pathPrefix.StartsWith("/")) { pathPrefix = "/" + pathPrefix; } ``` then it actually fails when performing a check: ```cs public async Task Invoke(HttpContext context) { if (context.Request.Path.StartsWithSegments(_pathPrefix)) { var didProxyRequest = await PerformProxyRequest(context); if (didProxyRequest) { return; } } ... ``` Here if ```_pathPrefix``` is "/" and ```context.Request.Path``` = "/7d8b1be5454ed9e44b78.hot-update.json" then ```StartsWithSegments``` will return false. Interesting that pathPrefix in ctor is actually an empty string (passed from WebpackDevMiddleware). That is why it was working for previous (preview2) version. The fix would be to skip inserting slash in case pathPrefix is an empty string. Or change the code of actual check in Invoke method. Please let me know if you want me to submit a pull request.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#507
No description provided.