Ejemplo n.º 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, IServiceProvider serviceProvider)
        {
            // intialize DBs
            MainDbContext mainDBContext = serviceProvider.GetService <MainDbContext>();

            mainDBContext.Initialize();

            AuthDbContext          authDbContext = serviceProvider.GetService <AuthDbContext>();
            UserManager <AuthUser> userManager   = serviceProvider.GetService <UserManager <AuthUser> >();

            authDbContext.Initialize(userManager);

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                // app.UseExceptionHandler("/Home/Error"); // todo: make nice error page
                app.UseHsts();
            }

#if DEBUG
            // Shows UseCors with CorsPolicyBuilder. // todo: wrap in developer environment only
            app.UseCors(builder =>
                        builder.AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials()
                        );

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger(); // https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger?tabs=visual-studio

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "SampleSolution Backend API V1");
            });
#endif

            app.UseHttpsRedirection();
            // app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseMvc();
        }