public HomeController(IUnitOfWork unitOfWork,
                       IHostEnvironment env,
                       NpmManager npmManager)
 {
     this.UnitOfWork = unitOfWork;
     this.env        = env;
     this.npmManager = npmManager;
 }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IWebHostEnvironment env,
                              FotografolioDbContext dbcontext)
        {
            NpmManager.CopyBuildFilesToPublicRoot(env);

            if (FotografolioDbContext.HerokuPostgreSqlConnectionString == null)
            {
                dbcontext.MigrateDatabse("Initial");
            }
            else
            {
                dbcontext.Database.Migrate();
            }

            if (!env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            app.UseHttpsRedirection();
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1");
            });
            app.UseRouting();
            if (CurrentEnvironment.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }
            else
            {
                app.UseStaticFiles();
            }
            //app.UseStaticFiles(new StaticFileOptions
            //{
            //    FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "clientapp/dist"))

            //app.UseCookieAuthentication(new CookieAuthenticationOptions()
            //{
            //    AuthenticationScheme = "Cookies",
            //    LoginPath = new PathString("/Account/Login/"),
            //    AutomaticAuthenticate = true
            //});
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                if (!CurrentEnvironment.IsDevelopment())
                {
                    endpoints.MapDefaultControllerRoute();
                    endpoints.MapFallbackToController("Index", "Home");
                }
                endpoints.MapControllers();
            });

            if (CurrentEnvironment.IsDevelopment())
            {
                app.UseSpa(spa =>
                {
                    if (env.IsDevelopment())
                    {
                        spa.Options.SourcePath = "clientapp";
                    }
                    else
                    {
                        spa.Options.SourcePath = "dist";
                    }

                    if (env.IsDevelopment())
                    {
                        spa.UseVueCli(npmScript: "serve");
                    }
                });
            }
        }