Merge pull request #1108 from aspnet/rel/2.0.0

Fix webpack HMR proxying logic for apps running on non-root URLs (e.g…
This commit is contained in:
Steve Sanderson
2017-07-11 18:57:03 +01:00
committed by GitHub
2 changed files with 7 additions and 2 deletions

View File

@@ -28,6 +28,11 @@ namespace Microsoft.AspNetCore.SpaServices.Webpack
string pathPrefix, string pathPrefix,
ConditionalProxyMiddlewareOptions options) ConditionalProxyMiddlewareOptions options)
{ {
if (!pathPrefix.StartsWith("/"))
{
pathPrefix = "/" + pathPrefix;
}
_next = next; _next = next;
_pathPrefix = pathPrefix; _pathPrefix = pathPrefix;
_options = options; _options = options;
@@ -65,7 +70,7 @@ namespace Microsoft.AspNetCore.SpaServices.Webpack
requestMessage.Headers.Host = _options.Host + ":" + _options.Port; requestMessage.Headers.Host = _options.Host + ":" + _options.Port;
var uriString = 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.RequestUri = new Uri(uriString);
requestMessage.Method = new HttpMethod(context.Request.Method); requestMessage.Method = new HttpMethod(context.Request.Method);

View File

@@ -101,9 +101,9 @@ namespace Microsoft.AspNetCore.Builder
// plus /__webpack_hmr is proxied with infinite timeout, because it's an EventSource (long-lived request). // plus /__webpack_hmr is proxied with infinite timeout, because it's an EventSource (long-lived request).
foreach (var publicPath in devServerInfo.PublicPaths) foreach (var publicPath in devServerInfo.PublicPaths)
{ {
appBuilder.UseProxyToLocalWebpackDevMiddleware(publicPath + hmrEndpoint, devServerInfo.Port, Timeout.InfiniteTimeSpan);
appBuilder.UseProxyToLocalWebpackDevMiddleware(publicPath, devServerInfo.Port, TimeSpan.FromSeconds(100)); 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) private static void UseProxyToLocalWebpackDevMiddleware(this IApplicationBuilder appBuilder, string publicPath, int proxyToPort, TimeSpan requestTimeout)