Sky.Net/API/Startup.cs

55 lines
1.7 KiB
C#
Raw Normal View History

2022-05-11 13:18:34 -07:00
using API.Extensions;
2022-05-10 16:49:42 -07:00
using API.Helpers;
2022-05-11 12:04:56 -07:00
using API.Middleware;
2022-05-09 18:31:09 -07:00
using Infrastructure.Data;
2022-05-09 14:41:15 -07:00
using Microsoft.EntityFrameworkCore;
namespace API
{
public class Startup
{
private readonly IConfiguration _config;
public Startup(IConfiguration config)
{
_config = config;
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
2022-05-11 13:18:34 -07:00
services.AddApplicationServices();
services.AddSwaggerDocumentation();
2022-05-09 14:41:15 -07:00
services.AddDbContext<StoreContext>(x => x.UseSqlite(_config.GetConnectionString("DefaultConnection")));
2022-05-10 16:49:42 -07:00
services.AddAutoMapper(typeof(MappingProfiles));
services.AddCors(opt =>
{
opt.AddPolicy("CorsPolicy", policy =>
{
policy.AllowAnyHeader().AllowAnyMethod().WithOrigins("https://localhost:4200");
});
});
2022-05-09 14:41:15 -07:00
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
2022-05-11 12:04:56 -07:00
app.UseMiddleware<ExceptionMiddleware>();
app.UseStatusCodePagesWithReExecute("/errors/{0}");
2022-05-09 14:41:15 -07:00
app.UseHttpsRedirection();
app.UseRouting();
2022-05-11 12:04:56 -07:00
app.UseStaticFiles();
app.UseCors("CorsPolicy");
2022-05-09 14:41:15 -07:00
app.UseAuthorization();
2022-05-11 13:18:34 -07:00
app.UseSwaggerDocumentation();
2022-05-09 14:41:15 -07:00
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}