HMR gets 404 on .hot-update.json #1191
Description
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.