Skip to content

Commit 5439412

Browse files
author
aligneddev
committed
fix cors for local
1 parent a2f27ff commit 5439412

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/BikeTracking.Api/Program.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@
4242

4343
builder.Services.AddEndpointsApiExplorer();
4444

45+
// Allow any localhost origin so the Vite dev server and published frontend
46+
// can reach the API during local Aspire orchestration. The origin port varies
47+
// per run so we match on host only, which is safe for local-only deployment.
48+
builder.Services.AddCors(options =>
49+
{
50+
options.AddDefaultPolicy(policy =>
51+
policy
52+
.SetIsOriginAllowed(origin => new Uri(origin).Host == "localhost")
53+
.AllowAnyHeader()
54+
.AllowAnyMethod()
55+
);
56+
});
57+
4558
var app = builder.Build();
4659

4760
await using (var scope = app.Services.CreateAsyncScope())
@@ -51,6 +64,7 @@
5164
}
5265

5366
app.MapGet("/", () => Results.Ok(new { message = "Bike Tracking API is running." }));
67+
app.UseCors();
5468
app.UseHttpLogging();
5569
app.MapUsersEndpoints();
5670
app.MapDefaultEndpoints();

0 commit comments

Comments
 (0)