diff options
| author | transtrike <transtrike@gmail.com> | 2021-02-13 16:20:18 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2021-02-13 16:20:18 +0200 |
| commit | 98e17766b203734a1817eed94338e2d25f4395f7 (patch) | |
| tree | 1266385a56cba56fd55c7faf661dd844bbdf5705 /src/Web/DevHive.Web/Startup.cs | |
| parent | 1ab34accfda22ee3ce5c7700e3b97ff3e932d649 (diff) | |
| download | DevHive-98e17766b203734a1817eed94338e2d25f4395f7.tar DevHive-98e17766b203734a1817eed94338e2d25f4395f7.tar.gz DevHive-98e17766b203734a1817eed94338e2d25f4395f7.zip | |
Project Restructure P.1
Diffstat (limited to 'src/Web/DevHive.Web/Startup.cs')
| -rw-r--r-- | src/Web/DevHive.Web/Startup.cs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/Web/DevHive.Web/Startup.cs b/src/Web/DevHive.Web/Startup.cs new file mode 100644 index 0000000..46521cf --- /dev/null +++ b/src/Web/DevHive.Web/Startup.cs @@ -0,0 +1,70 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using DevHive.Web.Configurations.Extensions; +using Newtonsoft.Json; + +namespace DevHive.Web +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddCors(); + + services.AddControllers() + .AddNewtonsoftJson(x => + { + x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; + }); + + services.DatabaseConfiguration(Configuration); + services.SwaggerConfiguration(); + services.JWTConfiguration(Configuration); + services.AutoMapperConfiguration(); + services.DependencyInjectionConfiguration(this.Configuration); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + app.UseCors(x => x + .AllowAnyMethod() + .AllowAnyHeader() + .SetIsOriginAllowed(origin => true) // allow any origin + .AllowCredentials()); // allow credentials + + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseSwaggerConfiguration(); + } + else + { + app.UseHsts(); + app.UseExceptionHandlerMiddlewareConfiguration(); + } + + app.UseDatabaseConfiguration(); + app.UseAutoMapperConfiguration(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllerRoute( + name: "default", + pattern: "api/{controller}/{action}" + ); + }); + } + } +} |
