Handle publicPath=/ in HMR. Fixes #1191.

This commit is contained in:
Steve Sanderson
2017-08-24 17:52:35 -07:00
parent e5f1299239
commit e2030fb1fa
2 changed files with 7 additions and 2 deletions

View File

@@ -22,6 +22,7 @@ namespace Microsoft.AspNetCore.SpaServices.Webpack
private readonly RequestDelegate _next; private readonly RequestDelegate _next;
private readonly ConditionalProxyMiddlewareOptions _options; private readonly ConditionalProxyMiddlewareOptions _options;
private readonly string _pathPrefix; private readonly string _pathPrefix;
private readonly bool _pathPrefixIsRoot;
public ConditionalProxyMiddleware( public ConditionalProxyMiddleware(
RequestDelegate next, RequestDelegate next,
@@ -35,6 +36,7 @@ namespace Microsoft.AspNetCore.SpaServices.Webpack
_next = next; _next = next;
_pathPrefix = pathPrefix; _pathPrefix = pathPrefix;
_pathPrefixIsRoot = string.Equals(_pathPrefix, "/", StringComparison.Ordinal);
_options = options; _options = options;
_httpClient = new HttpClient(new HttpClientHandler()); _httpClient = new HttpClient(new HttpClientHandler());
_httpClient.Timeout = _options.RequestTimeout; _httpClient.Timeout = _options.RequestTimeout;
@@ -42,7 +44,7 @@ namespace Microsoft.AspNetCore.SpaServices.Webpack
public async Task Invoke(HttpContext context) public async Task Invoke(HttpContext context)
{ {
if (context.Request.Path.StartsWithSegments(_pathPrefix)) if (context.Request.Path.StartsWithSegments(_pathPrefix) || _pathPrefixIsRoot)
{ {
var didProxyRequest = await PerformProxyRequest(context); var didProxyRequest = await PerformProxyRequest(context);
if (didProxyRequest) if (didProxyRequest)

View File

@@ -17,7 +17,10 @@ namespace Microsoft.AspNetCore.Builder
private static readonly JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings private static readonly JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings
{ {
ContractResolver = new CamelCasePropertyNamesContractResolver(), // Note that the aspnet-webpack JS code specifically expects options to be serialized with
// PascalCase property names, so it's important to be explicit about this contract resolver
ContractResolver = new DefaultContractResolver(),
TypeNameHandling = TypeNameHandling.None TypeNameHandling = TypeNameHandling.None
}; };