示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, AppConfig appConfig)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            if (env.IsDevelopment())
            {
                loggerFactory.AddDebug();
            }

            app.UseCors(builder =>
                        // This will allow any request from any server. Tweak to fit your needs!
                        builder.AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowAnyOrigin()
                        );

            app.UseJwtBearerAuthentication(new JwtBearerOptions
            {
                Audience              = appConfig.AuthConfig.ClientId,
                Authority             = appConfig.AuthConfig.Domain,
                AutomaticChallenge    = true,
                AutomaticAuthenticate = true,
                RequireHttpsMetadata  = appConfig.RequireHttpsMetadata,
                Events = new CmsApuJwtBearerEvents(app.ApplicationServices.GetRequiredService <CmsDbContext>())
            });

            app.UseMvc();

            // Enable middleware to serve generated Swagger as a JSON endpoint
            app.UseSwagger(c =>
            {
                c.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Host = httpReq.Host.Value);
            });
            app.UseSwaggerUi(c =>
            {
                c.SwaggerEndpoint("../v1/swagger.json", "HiPCMS API V1");
            });

            // Run all pending Migrations and Seed DB with initial data
            app.RunMigrationsAndSeedDb();
            app.UseStaticFiles();

            ServiceProvider = app.ApplicationServices;
        }
示例#2
0
 public static void AddAppSettings(this IServiceCollection services, IConfiguration Configuration)
 {
     AppConfig.Init(Configuration);
 }