public static IEndpointConventionBuilder MapVersionInfo(this IEndpointRouteBuilder builder, Action <VersionInfoOptions> setupOptions = null) { var options = new VersionInfoOptions(); setupOptions?.Invoke(options); var apiDelegate = builder.CreateApplicationBuilder() .UseMiddleware <ApiEndpoint>() .Build(); var apiEndpoint = builder.Map(options.ApiPath, apiDelegate) .WithDisplayName("VersionInfo API"); var uiDelegate = builder.CreateApplicationBuilder() .UseMiddleware <HtmlEndpoint>() .Build(); var uiEndpoint = builder.Map(options.HtmlPath, uiDelegate) .WithDisplayName("VersionInfo HTML"); var badgeDelegate = builder.CreateApplicationBuilder() .UseMiddleware <BadgeEndpoint>() .Build(); var badgeEndpoint = builder.Map(options.BadgePath, badgeDelegate) .WithDisplayName("VersionInfo Badge"); var endpointConventionBuilders = new List <IEndpointConventionBuilder>(new[] { apiEndpoint, uiEndpoint, badgeEndpoint }); return(new VersionInfoConventionBuilder(endpointConventionBuilders)); }
/// <summary> /// Adds endpoints for Features actions to the <see cref="IEndpointRouteBuilder"/>. And also display the UI. /// </summary> /// <param name="builder">The <see cref="IEndpointRouteBuilder"/>.</param> /// <returns>An <see cref="IEndpointConventionBuilder"/> for endpoints associated with controller actions.</returns> public static IEndpointConventionBuilder MapFeaturesUI(this IEndpointRouteBuilder builder) { var getAuthSchemesApiDelegate = builder.CreateApplicationBuilder() .UseMiddleware <GetAuthSchemesApiEndpointMiddleware>() .Build(); var getAllFeaturesApiDelegate = builder.CreateApplicationBuilder() .UseMiddleware <GetAllFeaturesApiEndpointMiddleware>() .Build(); var setFeatureApiDelegate = builder.CreateApplicationBuilder() .UseMiddleware <SetFeatureApiEndpointMiddleware>() .Build(); var getAuthSchemesApiEndpoint = builder.MapGet("/features/auth/schemes", getAuthSchemesApiDelegate) .WithDisplayName("Get Features auth schemes - UI Api"); var getAllfeaturesApiEndpoint = builder.MapGet("/features", getAllFeaturesApiDelegate) .WithDisplayName("Get all Features - UI Api"); var setFeatureApiEndpoint = builder.MapPost("/features/{featureName}/set", setFeatureApiDelegate) .WithDisplayName("Set Feature value - UI Api"); var apiEndpoints = new[] { getAuthSchemesApiEndpoint, getAllfeaturesApiEndpoint, setFeatureApiEndpoint }; var resourcesEndpoints = UIEndpointsResourceMapper.Map(builder, new Options()); var endpoints = apiEndpoints.Union(resourcesEndpoints); return(new FeaturesUIConventionBuilder(endpoints)); }
public static IEndpointConventionBuilder MapMetricsTextEndpoint(this IEndpointRouteBuilder endpoints) { var app = endpoints.CreateApplicationBuilder(); var responseWriter = GetMetricsTextResponseWriter(app.ApplicationServices); return(endpoints.Map("/metrics/text", endpoints.CreateApplicationBuilder().UseMiddleware <MetricsEndpointMiddleware>(responseWriter).Build())); }
public static IEndpointConventionBuilder MapEnvInfoEndpoint(this IEndpointRouteBuilder endpoints) { var app = endpoints.CreateApplicationBuilder(); var responseWriter = GetEnvInfoResponseWriter(app.ApplicationServices); return(endpoints.Map("/metrics/env", endpoints.CreateApplicationBuilder().UseMiddleware <EnvInfoMiddleware>(responseWriter).Build())); }
/// <summary> /// Maps the Blazor <see cref="Hub" /> to the path <paramref name="path"/>. /// </summary> /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/>.</param> /// <param name="path">The path to map the Blazor <see cref="Hub" />.</param> /// <param name="configureOptions">A callback to configure dispatcher options.</param> /// <returns>The <see cref="ComponentEndpointConventionBuilder"/>.</returns> public static ComponentEndpointConventionBuilder MapBlazorHub( this IEndpointRouteBuilder endpoints, string path, Action <HttpConnectionDispatcherOptions> configureOptions) { if (endpoints == null) { throw new ArgumentNullException(nameof(endpoints)); } if (path == null) { throw new ArgumentNullException(nameof(path)); } if (configureOptions == null) { throw new ArgumentNullException(nameof(configureOptions)); } var hubEndpoint = endpoints.MapHub <ComponentHub>(path, configureOptions); var disconnectEndpoint = endpoints.Map( (path.EndsWith('/') ? path : path + "/") + "disconnect/", endpoints.CreateApplicationBuilder().UseMiddleware <CircuitDisconnectMiddleware>().Build()) .WithDisplayName("Blazor disconnect"); var jsInitializersEndpoint = endpoints.Map( (path.EndsWith('/') ? path : path + "/") + "initializers/", endpoints.CreateApplicationBuilder().UseMiddleware <CircuitJavaScriptInitializationMiddleware>().Build()) .WithDisplayName("Blazor initializers"); return(new ComponentEndpointConventionBuilder(hubEndpoint, disconnectEndpoint, jsInitializersEndpoint)); }
public static IEndpointConventionBuilder MapHealthChecksUI(this IEndpointRouteBuilder builder, Action <Options> setupOptions = null) { var options = new Options(); setupOptions?.Invoke(options); EnsureValidApiOptions(options); var apiDelegate = builder.CreateApplicationBuilder() .UseMiddleware <UIApiEndpointMiddleware>() .Build(); var webhooksDelegate = builder.CreateApplicationBuilder() .UseMiddleware <UIWebHooksApiMiddleware>() .Build(); var embeddedResourcesAssembly = typeof(UIResource).Assembly; new UIEndpointsResourceMapper(new UIEmbeddedResourcesReader(embeddedResourcesAssembly)) .Map(builder, options); var apiEndpoint = builder.Map(options.ApiPath, apiDelegate) .WithDisplayName("HealthChecks UI Api"); var webhooksEndpoint = builder.Map(options.WebhookPath, webhooksDelegate) .WithDisplayName("HealthChecks UI Webhooks"); return(new HealthCheckUIConventionBuilder(apiEndpoint, webhooksEndpoint)); }
/// <summary> /// Maps the IDP endpoints to <paramref name="path"/>. /// </summary> /// <param name="builder">The <see cref="IEndpointRouteBuilder"/> to map the endpoints to.</param> /// <param name="path">The base path to map the endpoints to.</param> /// <returns>The <see cref="IEndpointRouteBuilder"/> instance so that additional calls can be chained.</returns> public static IEndpointRouteBuilder MapSaml2pIdentityProvider(this IEndpointRouteBuilder builder, PathString path) { var options = builder.ServiceProvider.GetRequiredService <IOptions <Saml2pOptions> >().Value; builder.Map(path.Add(options.AcceptPath), builder.CreateApplicationBuilder().UseAcceptSsoEndpoint(path).Build()).WithMetadata(new HttpMethodMetadata(new[] { HttpMethods.Get, HttpMethods.Post })); builder.Map(path.Add(options.InitiatePath), builder.CreateApplicationBuilder().UseInitiateSsoEndpoint(path).Build()).WithMetadata(new HttpMethodMetadata(new[] { HttpMethods.Get, HttpMethods.Post }));; builder.Map(path.Add(options.CompletePath), builder.CreateApplicationBuilder().UseCompleteSsoEndpoint(path).Build()).WithMetadata(new HttpMethodMetadata(new[] { HttpMethods.Get, HttpMethods.Post }));; return(builder); }
/// <summary> /// /// </summary> /// <param name="endpoints"></param> /// <param name="pattern"></param> /// <returns></returns> public static IEndpointRouteBuilder MapJsonQLTester(this IEndpointRouteBuilder endpoints, string pattern = "/jsonQL-tester") { endpoints.MapGet($"{pattern}/schema.json", endpoints.CreateApplicationBuilder().UseMiddleware <JsonQLTesterSchemaMiddleware>().Build()) .WithDisplayName("JsonQL Tester Schema"); endpoints.MapGet(pattern, endpoints.CreateApplicationBuilder().UseMiddleware <JsonQLTesterRedirectMiddleware>().Build()) .WithDisplayName("JsonQL Tester"); endpoints.MapGet($"{pattern}/{{file}}", CreateRequestDelegate(endpoints, pattern)) .WithDisplayName("JsonQL Tester Statics"); return(endpoints); }
/// <summary> /// Maps incoming requests with the specified path to the provided connection pipeline. /// </summary> /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param> /// <param name="pattern">The route pattern.</param> /// <param name="options">Options used to configure the connection.</param> /// <param name="configure">A callback to configure the connection.</param> /// <returns>An <see cref="ConnectionEndpointRouteBuilder"/> for endpoints associated with the connections.</returns> public static ConnectionEndpointRouteBuilder MapConnections(this IEndpointRouteBuilder endpoints, string pattern, HttpConnectionDispatcherOptions options, Action <IConnectionBuilder> configure) { var dispatcher = endpoints.ServiceProvider.GetRequiredService <HttpConnectionDispatcher>(); var connectionBuilder = new ConnectionBuilder(endpoints.ServiceProvider); configure(connectionBuilder); var connectionDelegate = connectionBuilder.Build(); // REVIEW: Consider expanding the internals of the dispatcher as endpoint routes instead of // using if statements we can let the matcher handle var conventionBuilders = new List <IEndpointConventionBuilder>(); // Build the negotiate application var app = endpoints.CreateApplicationBuilder(); app.UseWebSockets(); app.Run(c => dispatcher.ExecuteNegotiateAsync(c, options)); var negotiateHandler = app.Build(); var negotiateBuilder = endpoints.Map(pattern + "/negotiate", negotiateHandler); conventionBuilders.Add(negotiateBuilder); // Add the negotiate metadata so this endpoint can be identified negotiateBuilder.WithMetadata(_negotiateMetadata); negotiateBuilder.WithMetadata(options); // build the execute handler part of the protocol app = endpoints.CreateApplicationBuilder(); app.UseWebSockets(); app.Run(c => dispatcher.ExecuteAsync(c, options, connectionDelegate)); var executehandler = app.Build(); var executeBuilder = endpoints.Map(pattern, executehandler); conventionBuilders.Add(executeBuilder); var compositeConventionBuilder = new CompositeEndpointConventionBuilder(conventionBuilders); // Add metadata to all of Endpoints compositeConventionBuilder.Add(e => { // Add the authorization data as metadata foreach (var data in options.AuthorizationData) { e.Metadata.Add(data); } }); return(new ConnectionEndpointRouteBuilder(compositeConventionBuilder)); }
public static IEndpointConventionBuilder MapMiddlewareMethods(this IEndpointRouteBuilder endpoints, string pattern, IEnumerable <string> methods, Action <IApplicationBuilder> action) { var nested = endpoints.CreateApplicationBuilder(); action(nested); return(endpoints.MapMethods(pattern, methods, nested.Build())); }
public static IEndpointRouteBuilder MapCocoonProxyWithBlazor(this IEndpointRouteBuilder endpoints, IEnumerable <string> blazorPaths) { var cocoonProxy = endpoints.ServiceProvider.GetRequiredService <CocoonProxy>(); var blazorRoutes = new BlazorRoutes(blazorPaths); var app = endpoints.CreateApplicationBuilder(); app.Use(async(httpContext, next) => { if (blazorRoutes.Contains(httpContext.Request.Path)) { httpContext.Request.Path = "/index.html"; // Set endpoint to null so the static files middleware will handle the request. httpContext.SetEndpoint(null); await next(); return; } await cocoonProxy.ProxyAsync(httpContext); }); app.UseStaticFiles(); var func = app.Build(); endpoints.MapFallback("/{**catch-all}", func); return(endpoints); }
/// <summary> /// Adds Reverse Proxy routes to the route table with the customized processing pipeline. The pipeline includes /// by default the initialization step and the final proxy step, but not LoadBalancingMiddleware or other intermediate components. /// </summary> public static void MapReverseProxy(this IEndpointRouteBuilder endpoints, Action <IApplicationBuilder> configureApp) { if (endpoints is null) { throw new ArgumentNullException(nameof(endpoints)); } if (configureApp is null) { throw new ArgumentNullException(nameof(configureApp)); } var appBuilder = endpoints.CreateApplicationBuilder(); appBuilder.UseMiddleware <DestinationInitializerMiddleware>(); configureApp(appBuilder); appBuilder.UseMiddleware <ProxyInvokerMiddleware>(); var app = appBuilder.Build(); var routeBuilder = endpoints.ServiceProvider.GetRequiredService <IRuntimeRouteBuilder>(); routeBuilder.SetProxyPipeline(app); var configManager = endpoints.ServiceProvider.GetRequiredService <IProxyConfigManager>(); // Config validation is async but startup is sync. We want this to block so that A) any validation errors can prevent // the app from starting, and B) so that all the config is ready before the server starts accepting requests. // Reloads will be async. var dataSource = configManager.InitialLoadAsync().GetAwaiter().GetResult(); endpoints.DataSources.Add(dataSource); }
/// <summary> /// Adds a GraphQL schema SDL endpoint to the endpoint configurations. /// </summary> /// <param name="endpointRouteBuilder"> /// The <see cref="IEndpointConventionBuilder"/>. /// </param> /// <param name="pattern"> /// The path to which the GraphQL schema SDL endpoint shall be mapped. /// </param> /// <param name="schemaName"> /// The name of the schema that shall be used by this endpoint. /// </param> /// <returns> /// Returns the <see cref="IEndpointConventionBuilder"/> so that /// configuration can be chained. /// </returns> /// <exception cref="ArgumentNullException"> /// The <paramref name="endpointRouteBuilder" /> is <c>null</c>. /// </exception> public static IEndpointConventionBuilder MapGraphQLSchema( this IEndpointRouteBuilder endpointRouteBuilder, RoutePattern?pattern = default, NameString schemaName = default) { if (endpointRouteBuilder is null) { throw new ArgumentNullException(nameof(endpointRouteBuilder)); } pattern ??= Parse("/graphql/sdl"); IApplicationBuilder requestPipeline = endpointRouteBuilder.CreateApplicationBuilder(); NameString schemaNameOrDefault = schemaName.HasValue ? schemaName : Schema.DefaultName; requestPipeline .UseMiddleware <HttpGetSchemaMiddleware>( schemaNameOrDefault, MiddlewareRoutingType.Explicit) .Use(_ => context => { context.Response.StatusCode = 404; return(Task.CompletedTask); }); return(new GraphQLEndpointConventionBuilder( endpointRouteBuilder .Map(pattern, requestPipeline.Build()) .WithDisplayName("Hot Chocolate GraphQL Schema Pipeline"))); }
public static IEndpointConventionBuilder UseSoapEndpoint <T_MESSAGE>(this IEndpointRouteBuilder routes, Type type, string pattern, SoapEncoderOptions[] encoders, SoapSerializer serializer = SoapSerializer.DataContractSerializer, bool caseInsensitivePath = false, ISoapModelBounder soapModelBounder = null, Binding binding = null, WsdlFileOptions wsdlFileOptions = null, bool indentXml = true, bool omitXmlDeclaration = true) where T_MESSAGE : CustomMessage, new() { var options = new SoapOptions { Binding = binding, CaseInsensitivePath = caseInsensitivePath, EncoderOptions = encoders, Path = pattern, ServiceType = type, SoapSerializer = serializer, SoapModelBounder = soapModelBounder, WsdlFileOptions = wsdlFileOptions, IndentXml = indentXml, OmitXmlDeclaration = omitXmlDeclaration }; var pipeline = routes .CreateApplicationBuilder() .UseMiddleware <SoapEndpointMiddleware <T_MESSAGE> >(options) .Build(); return(routes.Map(pattern, pipeline) .WithDisplayName("SoapCore")); }
public static IEndpointConventionBuilder MapEasyData <THandler>( this IEndpointRouteBuilder builder, Action <EasyDataOptions> optionsTuner = null) where THandler : EasyDataApiHandler { var options = new EasyDataOptions(builder.ServiceProvider); optionsTuner?.Invoke(options); options.Endpoint = options.Endpoint.ToString().TrimEnd('/'); var pattern = RoutePatternFactory.Parse(options.Endpoint + "/{**slug}"); var app = builder.CreateApplicationBuilder(); app.UseMiddleware <EasyDataMiddleware <THandler> >(options); // return 404 if the request was not processed by EasyDataMiddleware // to prevent the exception on reaching the end of pipeline app.Run(context => { context.Response.StatusCode = 404; return(Task.CompletedTask); }); return(builder.Map(pattern, app.Build()) .WithDisplayName("EasyData API")); }
public static IEndpointConventionBuilder UseWeChatPayEndpoints(this IEndpointRouteBuilder endpoints) { var pipeline = endpoints.CreateApplicationBuilder() .UseMiddleware <WechatPayMiddleware>().Build(); return(endpoints.Map("/pay-api/{controller}/{action}", pipeline).WithDisplayName("wechatpay")); }
public static IEndpointConventionBuilder MapHangfireDashboard( [NotNull] this IEndpointRouteBuilder endpoints, [NotNull] string pattern, [CanBeNull] DashboardOptions options = null, [CanBeNull] JobStorage storage = null) { if (endpoints == null) { throw new ArgumentNullException(nameof(endpoints)); } if (pattern == null) { throw new ArgumentNullException(nameof(pattern)); } var app = endpoints.CreateApplicationBuilder(); HangfireServiceCollectionExtensions.ThrowIfNotConfigured(app.ApplicationServices); var services = app.ApplicationServices; storage = storage ?? services.GetRequiredService <JobStorage>(); options = options ?? services.GetService <DashboardOptions>() ?? new DashboardOptions(); options.TimeZoneResolver = options.TimeZoneResolver ?? services.GetService <ITimeZoneResolver>(); var routes = app.ApplicationServices.GetRequiredService <Dashboard.RouteCollection>(); var pipeline = app .UsePathBase(pattern) .UseMiddleware <AspNetCoreDashboardMiddleware>(storage, options, routes) .Build(); return(endpoints.Map(pattern + "/{**path}", pipeline)); }
// based on CreateRequestDelegate() https://github.com/aspnet/AspNetCore/blob/master/src/Middleware/StaticFiles/src/StaticFilesEndpointRouteBuilderExtensions.cs#L194 private static RequestDelegate CreateProxyRequestDelegate( IEndpointRouteBuilder endpoints, SpaOptions options, string npmScript, int port = 8080, ScriptRunnerType runner = ScriptRunnerType.Npm, string regex = VueCliMiddleware.DefaultRegex) { if (endpoints == null) { throw new ArgumentNullException(nameof(endpoints)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (npmScript == null) { throw new ArgumentNullException(nameof(npmScript)); } var app = endpoints.CreateApplicationBuilder(); app.Use(next => context => { // Set endpoint to null so the SPA middleware will handle the request. context.SetEndpoint(null); return next(context); }); app.UseSpa(opt => { if (options != null) { opt.Options.DefaultPage = options.DefaultPage; opt.Options.DefaultPageStaticFileOptions = options.DefaultPageStaticFileOptions; opt.Options.SourcePath = options.SourcePath; opt.Options.StartupTimeout = options.StartupTimeout; } opt.UseVueCli(npmScript, port, runner, regex); }); return app.Build(); }
private static RequestDelegate CreateRequestDelegate(IEndpointRouteBuilder endpoints, StaticFileOptions options) { var app = endpoints.CreateApplicationBuilder(); app.Use(next => context => { var endpoint = context.GetEndpoint(); var metadata = endpoint?.Metadata.GetMetadata <StaticFileEndpointMetadata>(); if (metadata == null) { throw new InvalidOperationException("Endpoint is missing metadata"); } context.Request.Path = metadata.Path; // Set endpoint to null so the static files middleware will handle the request. context.SetEndpoint(null); return(next(context)); }); app.UseStaticFiles(options); return(app.Build()); }
public static IEndpointConventionBuilder MapGraphQL( this IEndpointRouteBuilder endpointRouteBuilder, RoutePattern pattern, NameString schemaName = default) { if (endpointRouteBuilder == null) { throw new ArgumentNullException(nameof(endpointRouteBuilder)); } IApplicationBuilder requestPipeline = endpointRouteBuilder.CreateApplicationBuilder(); requestPipeline.UseMiddleware<WebSocketSubscriptionMiddleware>( schemaName.HasValue ? schemaName : Schema.DefaultName); requestPipeline.UseMiddleware<HttpPostMiddleware>( schemaName.HasValue ? schemaName : Schema.DefaultName); requestPipeline.UseMiddleware<HttpGetSchemaMiddleware>( schemaName.HasValue ? schemaName : Schema.DefaultName); requestPipeline.UseMiddleware<HttpGetMiddleware>( schemaName.HasValue ? schemaName : Schema.DefaultName); return endpointRouteBuilder .Map(pattern, requestPipeline.Build()) .WithDisplayName("Hot Chocolate GraphQL Pipeline"); }
/// <summary> /// Maps the <see cref="WebPubSubHub"/> to the path <paramref name="path"/>. /// </summary> /// <typeparam name="THub">User implemented <see cref="WebPubSubHub"/>.</typeparam> /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/>.</param> /// <param name="path">The path to map the <see cref="WebPubSubHub"/>.</param> /// <returns>The <see cref="IEndpointConventionBuilder"/>.</returns> public static IEndpointConventionBuilder MapWebPubSubHub <THub>( this IEndpointRouteBuilder endpoints, string path) where THub : WebPubSubHub { if (endpoints == null) { throw new ArgumentNullException(nameof(endpoints)); } var marker = endpoints.ServiceProvider.GetService <WebPubSubMarkerService>(); if (marker == null) { throw new InvalidOperationException( "Unable to find the required services. Please add all the required services by calling " + "'IServiceCollection.AddWebPubSub' inside the call to 'ConfigureServices(...)' in the application startup code."); } var adaptor = endpoints.ServiceProvider.GetService <ServiceRequestHandlerAdapter>(); adaptor.RegisterHub <THub>(); var app = endpoints.CreateApplicationBuilder(); app.UseMiddleware <WebPubSubMiddleware>(); return(endpoints.Map(path, app.Build())); }
public static IEndpointConventionBuilder MapMiddlewareRoute(this IEndpointRouteBuilder endpoints, string pattern, Action <IApplicationBuilder> action) { var nested = endpoints.CreateApplicationBuilder(); action(nested); return(endpoints.Map(pattern, nested.Build())); }
public static IEndpointConventionBuilder MapGraphQL( this IEndpointRouteBuilder endpointRouteBuilder, PathString path, NameString schemaName = default) { if (endpointRouteBuilder is null) { throw new ArgumentNullException(nameof(endpointRouteBuilder)); } path = path.ToString().TrimEnd('/'); RoutePattern pattern = RoutePatternFactory.Parse(path + "/{**slug}"); IApplicationBuilder requestPipeline = endpointRouteBuilder.CreateApplicationBuilder(); NameString schemaNameOrDefault = schemaName.HasValue ? schemaName : Schema.DefaultName; IFileProvider fileProvider = CreateFileProvider(); requestPipeline .UseMiddleware <WebSocketSubscriptionMiddleware>(schemaNameOrDefault) .UseMiddleware <HttpPostMiddleware>(schemaNameOrDefault) .UseMiddleware <HttpGetSchemaMiddleware>(schemaNameOrDefault) .UseMiddleware <ToolDefaultFileMiddleware>(fileProvider, path) .UseMiddleware <ToolOptionsFileMiddleware>(schemaNameOrDefault, path) .UseMiddleware <ToolStaticFileMiddleware>(fileProvider, path) .UseMiddleware <HttpGetMiddleware>(schemaNameOrDefault); return(endpointRouteBuilder .Map(pattern, requestPipeline.Build()) .WithDisplayName("Hot Chocolate GraphQL Pipeline")); }
/// <summary> /// Adds Reverse Proxy routes to the route table with the customized processing pipeline. The pipeline includes /// by default the initialization step and the final proxy step, but not LoadBalancingMiddleware or other intermediate components. /// </summary> public static void MapReverseProxy(this IEndpointRouteBuilder endpoints, Action <IApplicationBuilder> configureApp) { if (endpoints is null) { throw new ArgumentNullException(nameof(endpoints)); } if (configureApp is null) { throw new ArgumentNullException(nameof(configureApp)); } var appBuilder = endpoints.CreateApplicationBuilder(); appBuilder.UseMiddleware <DestinationInitializerMiddleware>(); configureApp(appBuilder); appBuilder.UseMiddleware <ProxyInvokerMiddleware>(); var app = appBuilder.Build(); var routeBuilder = endpoints.ServiceProvider.GetRequiredService <IRuntimeRouteBuilder>(); routeBuilder.SetProxyPipeline(app); var dataSource = (EndpointDataSource)endpoints.ServiceProvider.GetRequiredService <IProxyDynamicEndpointDataSource>(); endpoints.DataSources.Add(dataSource); }
private static RequestDelegate CreateRequestDelegate( IEndpointRouteBuilder builder, string filePath, StaticFileOptions options = null) { var app = builder.CreateApplicationBuilder(); app.Use(next => context => { context.Request.Path = "/" + filePath; // Set endpoint to null so the static files middleware will handle the request. context.SetEndpoint(null); return(next(context)); }); if (options == null) { app.UseStaticFiles(); } else { app.UseStaticFiles(options); } return(app.Build()); }
public static IEndpointRouteBuilder MapSwagger( this IEndpointRouteBuilder endpoints, string pattern = "/swagger/{documentName}/swagger.json", Action <SwaggerEndpointOptions> setupAction = null) { if (!RoutePatternFactory.Parse(pattern).Parameters.Any(x => x.Name == "documentName")) { throw new ArgumentException("Pattern must contain '{documentName}' parameter", nameof(pattern)); } Action <SwaggerOptions> endpointSetupAction = options => { var endpointOptions = new SwaggerEndpointOptions(); setupAction?.Invoke(endpointOptions); options.RouteTemplate = pattern; options.SerializeAsV2 = endpointOptions.SerializeAsV2; options.PreSerializeFilters.AddRange(endpointOptions.PreSerializeFilters); }; var pipeline = endpoints.CreateApplicationBuilder() .UseSwagger(endpointSetupAction) .Build(); endpoints.MapGet(pattern, pipeline); return(endpoints); }
public static IEndpointConventionBuilder UseSoapEndpoint <T, T_MESSAGE>(this IEndpointRouteBuilder routes, Action <SoapCoreOptions> options) where T_MESSAGE : CustomMessage, new() { var opt = new SoapCoreOptions(); options(opt); // Generate encoders from Binding when they are not provided if (opt.EncoderOptions is null && opt.Binding != null) { var elements = opt.Binding.CreateBindingElements().FindAll <MessageEncodingBindingElement>(); var encoderOptions = new SoapEncoderOptions[elements.Count]; for (var i = 0; i < encoderOptions.Length; i++) { var encoderOption = new SoapEncoderOptions { MessageVersion = elements[i].MessageVersion, WriteEncoding = Encoding.UTF8, ReaderQuotas = XmlDictionaryReaderQuotas.Max }; if (elements[i] is TextMessageEncodingBindingElement textMessageEncodingBindingElement) { encoderOption.WriteEncoding = textMessageEncodingBindingElement.WriteEncoding; encoderOption.ReaderQuotas = textMessageEncodingBindingElement.ReaderQuotas; } encoderOptions[i] = encoderOption; } opt.EncoderOptions = encoderOptions; } var soapOptions = new SoapOptions { ServiceType = typeof(T), Path = opt.Path, HttpsGetEnabled = opt.HttpsGetEnabled, HttpGetEnabled = opt.HttpGetEnabled, Binding = opt.Binding, CaseInsensitivePath = opt.CaseInsensitivePath, EncoderOptions = opt.EncoderOptions, SoapModelBounder = opt.SoapModelBounder, SoapSerializer = opt.SoapSerializer, BufferLimit = opt.BufferLimit, BufferThreshold = opt.BufferThreshold, OmitXmlDeclaration = opt.OmitXmlDeclaration, IndentXml = opt.IndentXml }; var pipeline = routes .CreateApplicationBuilder() .UseMiddleware <SoapEndpointMiddleware <T_MESSAGE> >(soapOptions) .Build(); return(routes.Map(soapOptions.Path, pipeline) .WithDisplayName("SoapCore")); }
public static IEndpointConventionBuilder MapTestTask(this IEndpointRouteBuilder endpoints, string pattern) { var pipeline = endpoints.CreateApplicationBuilder() .UseMiddleware <PingPongMiddleware>() .Build(); return(endpoints.Map(pattern, pipeline)); }
private static IEndpointConventionBuilder MapUpdate(this IEndpointRouteBuilder endpoints) { RequestDelegate pipeline = endpoints.CreateApplicationBuilder() .UseMiddleware <UpdateWebHookMiddleware>() .Build(); return(endpoints.MapPut("webhook/{id:guid}", pipeline)); }
private static IEndpointConventionBuilder MapQuery(this IEndpointRouteBuilder endpoints) { RequestDelegate pipeline = endpoints.CreateApplicationBuilder() .UseMiddleware <QueryWebHookMiddleware>() .Build(); return(endpoints.MapPost("webhook/query", pipeline)); }