Enable CORS for the Vite dev origin
This commit is contained in:
@@ -8,7 +8,14 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddDbContext<AppDbContext>(options =>
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("Postgres")));
|
||||
|
||||
// MARKER: CORS SERVICES
|
||||
const string DevCorsPolicy = "DevCors";
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy(DevCorsPolicy, policy => policy
|
||||
.WithOrigins("http://localhost:5173")
|
||||
.AllowAnyHeader()
|
||||
.WithMethods("GET", "POST", "PATCH", "DELETE"));
|
||||
});
|
||||
|
||||
builder.Services
|
||||
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
@@ -37,7 +44,10 @@ builder.Services.AddControllers();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// MARKER: CORS MIDDLEWARE
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseCors(DevCorsPolicy);
|
||||
}
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
Reference in New Issue
Block a user