GGMM/GrossesMitaines/GrossesMitainesAPI/Program.cs

40 lines
1.2 KiB
C#
Raw Normal View History

2022-10-08 14:02:05 -04:00
using GrossesMitainesAPI.Data;
using Microsoft.EntityFrameworkCore;
2022-10-17 16:07:59 -04:00
var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
2022-09-27 14:26:56 -04:00
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
2022-10-17 16:07:59 -04:00
builder.Services.AddCors(options => {
options.AddPolicy(name: MyAllowSpecificOrigins,
policy => {
policy.WithOrigins("http://localhost:3000",
2022-10-18 10:08:23 -04:00
"http://localhost:3001")
.AllowAnyMethod()
.AllowAnyHeader();
2022-10-17 16:07:59 -04:00
});
});
2022-09-27 14:26:56 -04:00
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
2022-10-08 14:02:05 -04:00
builder.Services.AddDbContextFactory<InventoryContext>(options => { options.UseSqlServer("DefaultConnection"); });
2022-09-27 14:26:56 -04:00
var app = builder.Build();
// Configure the HTTP request pipeline.
2022-10-08 14:02:05 -04:00
if (app.Environment.IsDevelopment()) {
2022-09-27 14:26:56 -04:00
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
2022-10-17 16:07:59 -04:00
app.UseCors(MyAllowSpecificOrigins);
2022-09-27 14:26:56 -04:00
app.UseAuthorization();
app.MapControllers();
2022-10-17 16:07:59 -04:00
app.Run();