Skip to content

Commit f048038

Browse files
authoredFeb 16, 2021
Make sure Angular CLI middleware supports "ng serve --ssl" (dotnet#27799)
* Make sure Angular CLI middleware supports "ng serve --ssl" by listening to full URL returned by Angular CLI. * Removed redundant AngularCliServerInfo class.
1 parent e78cf3d commit f048038

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed
 

‎src/Middleware/SpaServices.Extensions/src/AngularCli/AngularCliMiddleware.cs

+3-17
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,19 @@ public static void Attach(
4848
var diagnosticSource = appBuilder.ApplicationServices.GetRequiredService<DiagnosticSource>();
4949
var angularCliServerInfoTask = StartAngularCliServerAsync(sourcePath, scriptName, pkgManagerCommand, devServerPort, logger, diagnosticSource, applicationStoppingToken);
5050

51-
// Everything we proxy is hardcoded to target http://localhost because:
52-
// - the requests are always from the local machine (we're not accepting remote
53-
// requests that go directly to the Angular CLI middleware server)
54-
// - given that, there's no reason to use https, and we couldn't even if we
55-
// wanted to, because in general the Angular CLI server has no certificate
56-
var targetUriTask = angularCliServerInfoTask.ContinueWith(
57-
task => new UriBuilder("http", "localhost", task.Result.Port).Uri);
58-
5951
SpaProxyingExtensions.UseProxyToSpaDevelopmentServer(spaBuilder, () =>
6052
{
6153
// On each request, we create a separate startup task with its own timeout. That way, even if
6254
// the first request times out, subsequent requests could still work.
6355
var timeout = spaBuilder.Options.StartupTimeout;
64-
return targetUriTask.WithTimeout(timeout,
56+
return angularCliServerInfoTask.WithTimeout(timeout,
6557
$"The Angular CLI process did not start listening for requests " +
6658
$"within the timeout period of {timeout.TotalSeconds} seconds. " +
6759
$"Check the log output for error information.");
6860
});
6961
}
7062

71-
private static async Task<AngularCliServerInfo> StartAngularCliServerAsync(
63+
private static async Task<Uri> StartAngularCliServerAsync(
7264
string sourcePath, string scriptName, string pkgManagerCommand, int portNumber, ILogger logger, DiagnosticSource diagnosticSource, CancellationToken applicationStoppingToken)
7365
{
7466
if (portNumber == default(int))
@@ -99,13 +91,12 @@ private static async Task<AngularCliServerInfo> StartAngularCliServerAsync(
9991
}
10092

10193
var uri = new Uri(openBrowserLine.Groups[1].Value);
102-
var serverInfo = new AngularCliServerInfo { Port = uri.Port };
10394

10495
// Even after the Angular CLI claims to be listening for requests, there's a short
10596
// period where it will give an error if you make a request too quickly
10697
await WaitForAngularCliServerToAcceptRequests(uri);
10798

108-
return serverInfo;
99+
return uri;
109100
}
110101

111102
private static async Task WaitForAngularCliServerToAcceptRequests(Uri cliServerUri)
@@ -146,10 +137,5 @@ await client.SendAsync(
146137
}
147138
}
148139
}
149-
150-
class AngularCliServerInfo
151-
{
152-
public int Port { get; set; }
153-
}
154140
}
155141
}

0 commit comments

Comments
 (0)
Please sign in to comment.