Created
February 17, 2025 20:20
-
-
Save dontpaniclabsgists/9aeb77e77e2085ac85b339a0ecc8d499 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var builder = WebApplication.CreateBuilder(args); | |
// Add services to the container. | |
builder.Services.AddControllers(); | |
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | |
builder.Services.AddEndpointsApiExplorer(); | |
builder.Services.AddSwaggerGen(); | |
// Configure CORS | |
builder.Services.AddCors(options => | |
{ | |
options.AddDefaultPolicy(builder => | |
{ | |
builder.WithOrigins("https://localhost:62402") // Frontend URL | |
.AllowAnyHeader() | |
.AllowAnyMethod(); | |
}); | |
}); | |
var app = builder.Build(); | |
// Use CORS | |
app.UseCors(); | |
app.UseDefaultFiles(); | |
app.UseStaticFiles(); | |
// Configure the HTTP request pipeline. | |
if (app.Environment.IsDevelopment()) | |
{ | |
app.UseSwagger(); | |
app.UseSwaggerUI(); | |
} | |
app.UseHttpsRedirection(); | |
app.UseAuthorization(); | |
app.MapControllers(); | |
app.MapFallbackToFile("/index.html"); | |
app.Run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment