2022-10-08 14:02:05 -04:00
|
|
|
using GrossesMitainesAPI.Data;
|
2022-10-21 17:52:25 -04:00
|
|
|
using GrossesMitainesAPI.Services;
|
2022-10-30 16:58:47 -04:00
|
|
|
using Microsoft.AspNet.Identity;
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
2022-10-08 14:02:05 -04:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-10-30 16:58:47 -04:00
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using System.Net;
|
2022-10-08 14:02:05 -04:00
|
|
|
|
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")
|
2022-10-18 11:50:06 -04:00
|
|
|
.AllowAnyMethod()
|
|
|
|
.AllowAnyHeader();
|
2022-10-17 16:07:59 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-27 14:26:56 -04:00
|
|
|
builder.Services.AddControllers();
|
2022-10-30 16:58:47 -04:00
|
|
|
|
|
|
|
builder.Services.AddAuthentication("Cookies").AddIdentityCookies();
|
|
|
|
builder.Services.AddIdentityCore<InventoryUser>()
|
|
|
|
.AddRoles<IdentityRole>()
|
|
|
|
.AddEntityFrameworkStores<InventoryContext>()
|
|
|
|
.AddSignInManager();
|
|
|
|
|
2022-09-27 14:26:56 -04:00
|
|
|
// 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-10-21 17:52:25 -04:00
|
|
|
builder.Services.AddSingleton<DatabaseCacheService>();
|
|
|
|
builder.Services.BuildServiceProvider().GetRequiredService<DatabaseCacheService>();
|
|
|
|
|
2022-10-30 16:58:47 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
2022-10-30 16:58:47 -04:00
|
|
|
app.UseAuthentication();
|
2022-09-27 14:26:56 -04:00
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
|
2022-10-17 16:07:59 -04:00
|
|
|
app.Run();
|