public static void UseProxyToSpaDevelopmentServer( this ISeedSpaBuilder spaBuilder, string baseUri) { UseProxyToSpaDevelopmentServer( spaBuilder, new Uri(baseUri)); }
public static void UseProxyToSpaDevelopmentServer( this ISeedSpaBuilder spaBuilder, Uri baseUri) { UseProxyToSpaDevelopmentServer( spaBuilder, () => Task.FromResult(baseUri)); }
public static void UseSpaDevelopmentServer(this ISeedSpaBuilder spaBuilder, string npmScript) { if (spaBuilder == null) { throw new ArgumentNullException(nameof(spaBuilder)); } SpaServiceMiddleware.Attach(spaBuilder, npmScript); }
public static void Attach( ISeedSpaBuilder spaBuilder, string scriptName) { var attribute = spaBuilder.Assembly.GetCustomAttribute <SpaProjectAttribute>(); var sourcePath = Path.Combine(attribute.Project, attribute.Path); var pkgManagerCommand = spaBuilder.Server.PkgManagerCommand; var devServerPort = spaBuilder.Server.DevServerPort; if (!Directory.Exists(sourcePath)) { return; } if (string.IsNullOrEmpty(scriptName)) { throw new ArgumentException("Cannot be null or empty", nameof(scriptName)); } var appBuilder = spaBuilder.ApplicationBuilder; var applicationStoppingToken = appBuilder.ApplicationServices.GetRequiredService <IHostApplicationLifetime>().ApplicationStopping; var logger = LoggerFinder.GetOrCreateLogger(appBuilder, LogCategoryName); var diagnosticSource = appBuilder.ApplicationServices.GetRequiredService <DiagnosticSource>(); var portTask = StartCreateAppServerAsync( sourcePath, scriptName, pkgManagerCommand, devServerPort, spaBuilder.Server.SuccessRegx, spaBuilder.Assembly.GetName().Name, logger, diagnosticSource, applicationStoppingToken); var targetUriTask = portTask.ContinueWith( task => new UriBuilder("http", "localhost", task.Result).Uri); SeedSpaBuilderExtensions.UseProxyToSpaDevelopmentServer(spaBuilder, () => { var timeout = spaBuilder.Options.StartupTimeout; return(targetUriTask.WithTimeout(timeout, $"The server did not start listening for requests " + $"within the timeout period of {timeout.Seconds} seconds. " + $"Check the log output for error information.")); }); }
public static void UseProxyToSpaDevelopmentServer( this ISeedSpaBuilder spaBuilder, Func <Task <Uri> > baseUriTaskFactory) { var applicationBuilder = spaBuilder.ApplicationBuilder; var applicationStoppingToken = GetStoppingToken(applicationBuilder); var assemblyName = spaBuilder.Assembly.GetName().Name; if (!SeedSpaBuilderExtensions.UrlHash.ContainsKey(assemblyName)) { SeedSpaBuilderExtensions.UrlHash.Add(assemblyName, baseUriTaskFactory); } applicationBuilder.UseWebSockets(); var neverTimeOutHttpClient = SpaProxy.CreateHttpClientForProxy(Timeout.InfiniteTimeSpan); applicationBuilder.Use(async(context, next) => { if (context.GetEndpoint() == null && context.Request.Path.Value.StartsWith($"/{assemblyName}")) { await SpaProxy.PerformProxyRequest( context, neverTimeOutHttpClient, baseUriTaskFactory(), applicationStoppingToken, proxy404s: true); return; } await next(); }); }