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));
        }
Beispiel #2
0
 public HtmlEndpoint(
     RequestDelegate next,
     IWebHostEnvironment hostingEnv,
     ILoggerFactory loggerFactory,
     VersionInfoOptions options = null)
 {
     _options = options ?? new VersionInfoOptions();
     _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, _options);
 }
Beispiel #3
0
        private StaticFileMiddleware CreateStaticFileMiddleware(
            RequestDelegate next,
            IWebHostEnvironment hostingEnv,
            ILoggerFactory loggerFactory,
            VersionInfoOptions options)
        {
            var staticFileOptions = new StaticFileOptions
            {
                RequestPath  = string.IsNullOrEmpty(options.RoutePrefix) ? string.Empty : $"/{options.RoutePrefix}",
                FileProvider = new EmbeddedFileProvider(typeof(HtmlEndpoint).Assembly, EmbeddedFileNamespace),
            };

            return(new StaticFileMiddleware(next, hostingEnv, Options.Create(staticFileOptions), loggerFactory));
        }