Skip to content

Instantly share code, notes, and snippets.

@dontpaniclabsgists
Created February 17, 2025 20:20
Show Gist options
  • Save dontpaniclabsgists/9aeb77e77e2085ac85b339a0ecc8d499 to your computer and use it in GitHub Desktop.
Save dontpaniclabsgists/9aeb77e77e2085ac85b339a0ecc8d499 to your computer and use it in GitHub Desktop.
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