diff --git a/src/Recollections.Api/Accounts/AccountsStartup.cs b/src/Recollections.Api/Accounts/AccountsStartup.cs index da7c81c..29bf7fe 100644 --- a/src/Recollections.Api/Accounts/AccountsStartup.cs +++ b/src/Recollections.Api/Accounts/AccountsStartup.cs @@ -93,9 +93,10 @@ private static void EnsureDatabase(IServiceCollection services) } } - public void ConfigureAuthentication(IApplicationBuilder app, IHostingEnvironment env) + public void ConfigureAuthentication(IApplicationBuilder app, IWebHostEnvironment env) { app.UseAuthentication(); + app.UseAuthorization(); } } } diff --git a/src/Recollections.Api/Recollections.Api.csproj b/src/Recollections.Api/Recollections.Api.csproj index a4c9bb2..14de61e 100644 --- a/src/Recollections.Api/Recollections.Api.csproj +++ b/src/Recollections.Api/Recollections.Api.csproj @@ -11,6 +11,7 @@ + diff --git a/src/Recollections.Api/Startup.cs b/src/Recollections.Api/Startup.cs index b07d746..2904adc 100644 --- a/src/Recollections.Api/Startup.cs +++ b/src/Recollections.Api/Startup.cs @@ -4,10 +4,9 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Neptuo; +using Microsoft.Extensions.Hosting; using Neptuo.Recollections.Accounts; using Neptuo.Recollections.Entries; @@ -17,11 +16,11 @@ namespace Neptuo.Recollections public class Startup { - private readonly IHostingEnvironment environment; + private readonly IWebHostEnvironment environment; private readonly AccountsStartup accountsStartup; private readonly EntriesStartup entriesStartup; - public Startup(IConfiguration configuration, IHostingEnvironment environment) + public Startup(IConfiguration configuration, IWebHostEnvironment environment) { Ensure.NotNull(environment, "environment"); this.environment = environment; @@ -35,23 +34,34 @@ public Startup(IConfiguration configuration, IHostingEnvironment environment) public void ConfigureServices(IServiceCollection services) { services.AddSingleton(ResolvePath); - services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + + services + .AddRouting(options => options.LowercaseUrls = true) + .AddControllers() + .AddNewtonsoftJson(); + accountsStartup.ConfigureServices(services); entriesStartup.ConfigureServices(services); } - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app) { - if (env.IsDevelopment()) + if (environment.IsDevelopment()) app.UseDeveloperExceptionPage(); else app.UseStatusCodePages(); + app.UseRouting(); + UseCors(app); - accountsStartup.ConfigureAuthentication(app, env); + accountsStartup.ConfigureAuthentication(app, environment); - app.UseMvc(); + app.UseEndpoints(endpoints => + { + endpoints.MapHealthChecks("/health"); + endpoints.MapControllers(); + }); } private static void UseCors(IApplicationBuilder app) @@ -68,8 +78,6 @@ private static void UseCors(IApplicationBuilder app) p.AllowAnyHeader(); p.SetPreflightMaxAge(TimeSpan.FromMinutes(10)); }); - - app.UseHealthChecks("/health"); } } }