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

Commit 26d666d

Browse files
Allow configuration of SPA startup timeout. Part of #1447
1 parent e024e5b commit 26d666d

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

src/Microsoft.AspNetCore.SpaServices.Extensions/AngularCli/AngularCliMiddleware.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ internal static class AngularCliMiddleware
2020
{
2121
private const string LogCategoryName = "Microsoft.AspNetCore.SpaServices";
2222
private static TimeSpan RegexMatchTimeout = TimeSpan.FromSeconds(5); // This is a development-time only feature, so a very long timeout is fine
23-
private static TimeSpan StartupTimeout = TimeSpan.FromSeconds(50); // Note that the HTTP request itself by default times out after 60s, so you only get useful error information if this is shorter
2423

2524
public static void Attach(
2625
ISpaBuilder spaBuilder,
@@ -54,9 +53,10 @@ public static void Attach(
5453
{
5554
// On each request, we create a separate startup task with its own timeout. That way, even if
5655
// the first request times out, subsequent requests could still work.
57-
return targetUriTask.WithTimeout(StartupTimeout,
56+
var timeout = spaBuilder.Options.StartupTimeout;
57+
return targetUriTask.WithTimeout(timeout,
5858
$"The Angular CLI process did not start listening for requests " +
59-
$"within the timeout period of {StartupTimeout.Seconds} seconds. " +
59+
$"within the timeout period of {timeout.Seconds} seconds. " +
6060
$"Check the log output for error information.");
6161
});
6262
}

src/Microsoft.AspNetCore.SpaServices.Extensions/Prerendering/SpaPrerenderingExtensions.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ namespace Microsoft.AspNetCore.Builder
2424
/// </summary>
2525
public static class SpaPrerenderingExtensions
2626
{
27-
private static TimeSpan BuildTimeout = TimeSpan.FromSeconds(50); // Note that the HTTP request itself by default times out after 60s, so you only get useful error information if this is shorter
28-
2927
/// <summary>
3028
/// Enables server-side prerendering middleware for a Single Page Application.
3129
/// </summary>
@@ -71,6 +69,7 @@ public static void UseSpaPrerendering(
7169
var excludePathStrings = (options.ExcludeUrls ?? Array.Empty<string>())
7270
.Select(url => new PathString(url))
7371
.ToArray();
72+
var buildTimeout = spaBuilder.Options.StartupTimeout;
7473

7574
applicationBuilder.Use(async (context, next) =>
7675
{
@@ -93,9 +92,9 @@ public static void UseSpaPrerendering(
9392
// For better debuggability, create a per-request timeout that makes it clear if the
9493
// prerendering builder took too long for this request, but without aborting the
9594
// underlying build task so that subsequent requests could still work.
96-
await buildOnDemandTask.WithTimeout(BuildTimeout,
95+
await buildOnDemandTask.WithTimeout(buildTimeout,
9796
$"The prerendering build process did not complete within the " +
98-
$"timeout period of {BuildTimeout.Seconds} seconds. " +
97+
$"timeout period of {buildTimeout.Seconds} seconds. " +
9998
$"Check the log output for error information.");
10099
}
101100

src/Microsoft.AspNetCore.SpaServices.Extensions/ReactDevelopmentServer/ReactDevelopmentServerMiddleware.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ internal static class ReactDevelopmentServerMiddleware
1919
{
2020
private const string LogCategoryName = "Microsoft.AspNetCore.SpaServices";
2121
private static TimeSpan RegexMatchTimeout = TimeSpan.FromSeconds(5); // This is a development-time only feature, so a very long timeout is fine
22-
private static TimeSpan StartupTimeout = TimeSpan.FromSeconds(50); // Note that the HTTP request itself by default times out after 60s, so you only get useful error information if this is shorter
2322

2423
public static void Attach(
2524
ISpaBuilder spaBuilder,
@@ -53,9 +52,10 @@ public static void Attach(
5352
{
5453
// On each request, we create a separate startup task with its own timeout. That way, even if
5554
// the first request times out, subsequent requests could still work.
56-
return targetUriTask.WithTimeout(StartupTimeout,
55+
var timeout = spaBuilder.Options.StartupTimeout;
56+
return targetUriTask.WithTimeout(timeout,
5757
$"The create-react-app server did not start listening for requests " +
58-
$"within the timeout period of {StartupTimeout.Seconds} seconds. " +
58+
$"within the timeout period of {timeout.Seconds} seconds. " +
5959
$"Check the log output for error information.");
6060
});
6161
}

src/Microsoft.AspNetCore.SpaServices.Extensions/SpaOptions.cs

+6
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,11 @@ public PathString DefaultPage
6767
/// development. The directory may not exist in published applications.
6868
/// </summary>
6969
public string SourcePath { get; set; }
70+
71+
/// <summary>
72+
/// Gets or sets the maximum duration that a request will wait for the SPA
73+
/// to become ready to serve to the client.
74+
/// </summary>
75+
public TimeSpan StartupTimeout { get; set; } = TimeSpan.FromSeconds(50);
7076
}
7177
}

0 commit comments

Comments
 (0)