コード例 #1
0
ファイル: Startup.cs プロジェクト: RouR/ToDo-ToBuy
        public void Configure(IApplicationBuilder app, IApplicationLifetime applicationLifetime,
                              ILoggerFactory loggerFactory)
        {
            //var configuration = app.ApplicationServices.GetService<TelemetryConfiguration>();
            //configuration.DisableTelemetry = true;

            CustomLogs.SetupCustomLogs.Configure(loggerFactory, applicationLifetime);
            SetupDefaultWebMetrics.Configure(app);

            app.ApiKeyMiddleware();
            KeyHeaderChecker.SetApiKey(ServiceClients.GetApiKey(Service.ToBuy));

            app.UseStaticFiles();
            app.UseMvc(routes =>
            {
                //routes.MapRoute(
                //    name: "areas",
                //    template: "{area:exists}/{controller=Home}/{action=Index}");
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}"
                    //defaults: new {area = "home", controller = "Hello", action = "Index"}
                    );
            });
        }
コード例 #2
0
        public void Configure(IApplicationBuilder app, IApplicationLifetime applicationLifetime,
                              ILoggerFactory loggerFactory, IApiVersionDescriptionProvider provider,
                              IHostingEnvironment env
                              )
        {
            //var configuration = app.ApplicationServices.GetService<TelemetryConfiguration>();
            //configuration.DisableTelemetry = true;

            CustomLogs.SetupCustomLogs.Configure(loggerFactory, applicationLifetime);
            SetupDefaultWebMetrics.Configure(app);

            var cachePeriod = env.IsDevelopment() ? 0 : 10 /*d*/ * 24 /*h*/ * 60 /*m*/ * 60 /*s*/;

            app.UseStaticFiles(new StaticFileOptions
            {
                OnPrepareResponse = ctx =>
                {
                    // Requires the following import:
                    // using Microsoft.AspNetCore.Http;
                    if (cachePeriod > 0)
                    {
                        ctx.Context.Response.Headers.Append("Cache-Control", $"public, max-age={cachePeriod}");
                    }
                    else
                    {
                        ctx.Context.Response.Headers.Append("Cache-Control", $" no-cache, no-store, must-revalidate ");
                    }
                }
            });

            //todo: check headers not in minikube, with real ingress
            //app.UseIpRateLimiting();

            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials()
                        );
            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "areas",
                    template: "{area:exists}/{controller=Home}/{action=Index}");
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { area = "home", controller = "Hello", action = "Index" });
            });

            app.UseSwagger();
            app.UseSwaggerUI(
                options =>
            {
                // build a swagger endpoint for each discovered API version
                foreach (var description in provider.ApiVersionDescriptions)
                {
                    options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json",
                                            description.GroupName.ToUpperInvariant());
                }
            });
        }