Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

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

Closed
offbeatful opened this issue Aug 15, 2017 · 6 comments
Closed

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

offbeatful opened this issue Aug 15, 2017 · 6 comments

Comments

@offbeatful
Copy link

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.

@MarkPieszak
Copy link
Contributor

I'm wondering if this is what's causing the EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection. that's causing HMR not to work as well.

@SteveSandersonMS
Copy link
Member

Thanks for reporting this. It's now fixed.

@spnm
Copy link

spnm commented Aug 28, 2017

is there a quick workaround for this?
thank you

@offbeatful
Copy link
Author

@spnm , yes. You will need to change publicPath to something different for development build only.

Assume you have isProduction variable then the code in your webpack.config will look like this:

if (!isProduction) {
    clientConfig.output.publicPath = "_/";
    serverConfig.output.publicPath = "_/";
}

I have a fully functional example/template here:
https://github.com/mocoding-software/spa-template

@offbeatful
Copy link
Author

This bug is not fixed.
New workaround:

if (!isProduction) {
    clientConfig.output.publicPath = "/_/";
    serverConfig.output.publicPath = "/_/";
}

@andersstorhaug
Copy link

Looks like this may be fixed in the dev branch but not part of 2.0.1?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants