42 lines
1.0 KiB
C#
42 lines
1.0 KiB
C#
|
|
using FateMaster.API.Data;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
|
||
|
|
var builder = WebApplication.CreateBuilder(args);
|
||
|
|
|
||
|
|
// Add services to the container.
|
||
|
|
builder.Services.AddControllers();
|
||
|
|
builder.Services.AddEndpointsApiExplorer();
|
||
|
|
builder.Services.AddSwaggerGen();
|
||
|
|
|
||
|
|
// Configure MySQL
|
||
|
|
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
||
|
|
builder.Services.AddDbContext<ApplicationDbContext>(options =>
|
||
|
|
options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)));
|
||
|
|
|
||
|
|
// Configure CORS
|
||
|
|
builder.Services.AddCors(options =>
|
||
|
|
{
|
||
|
|
options.AddPolicy("AllowFrontend", policy =>
|
||
|
|
{
|
||
|
|
policy.WithOrigins("http://localhost:3000", "http://localhost:3001")
|
||
|
|
.AllowAnyMethod()
|
||
|
|
.AllowAnyHeader()
|
||
|
|
.AllowCredentials();
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
var app = builder.Build();
|
||
|
|
|
||
|
|
// Configure the HTTP request pipeline.
|
||
|
|
if (app.Environment.IsDevelopment())
|
||
|
|
{
|
||
|
|
app.UseSwagger();
|
||
|
|
app.UseSwaggerUI();
|
||
|
|
}
|
||
|
|
|
||
|
|
app.UseCors("AllowFrontend");
|
||
|
|
app.UseAuthorization();
|
||
|
|
app.MapControllers();
|
||
|
|
|
||
|
|
app.Run();
|