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

Commit

Permalink
Fix webpack HMR proxying logic for apps running on non-root URLs (e.g…
Browse files Browse the repository at this point in the history
…., full IIS virtual directories)
  • Loading branch information
SteveSandersonMS committed Jul 11, 2017
1 parent 22ff88a commit 44f86eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public ConditionalProxyMiddleware(
string pathPrefix,
ConditionalProxyMiddlewareOptions options)
{
if (!pathPrefix.StartsWith("/"))
{
pathPrefix = "/" + pathPrefix;
}

_next = next;
_pathPrefix = pathPrefix;
_options = options;
Expand Down Expand Up @@ -65,7 +70,7 @@ private async Task<bool> PerformProxyRequest(HttpContext context)

requestMessage.Headers.Host = _options.Host + ":" + _options.Port;
var uriString =
$"{_options.Scheme}://{_options.Host}:{_options.Port}{context.Request.PathBase}{context.Request.Path}{context.Request.QueryString}";
$"{_options.Scheme}://{_options.Host}:{_options.Port}{context.Request.Path}{context.Request.QueryString}";
requestMessage.RequestUri = new Uri(uriString);
requestMessage.Method = new HttpMethod(context.Request.Method);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public static void UseWebpackDevMiddleware(
// plus /__webpack_hmr is proxied with infinite timeout, because it's an EventSource (long-lived request).
foreach (var publicPath in devServerInfo.PublicPaths)
{
appBuilder.UseProxyToLocalWebpackDevMiddleware(publicPath + hmrEndpoint, devServerInfo.Port, Timeout.InfiniteTimeSpan);
appBuilder.UseProxyToLocalWebpackDevMiddleware(publicPath, devServerInfo.Port, TimeSpan.FromSeconds(100));
}
appBuilder.UseProxyToLocalWebpackDevMiddleware(hmrEndpoint, devServerInfo.Port, Timeout.InfiniteTimeSpan);
}

private static void UseProxyToLocalWebpackDevMiddleware(this IApplicationBuilder appBuilder, string publicPath, int proxyToPort, TimeSpan requestTimeout)
Expand Down

0 comments on commit 44f86eb

Please sign in to comment.