Skip to content

Commit

Permalink
fix: 增加CORS设置允许浏览器跨域请求
Browse files Browse the repository at this point in the history
  • Loading branch information
gnattu committed Oct 25, 2023
1 parent e78cd2a commit 5d6623c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions BBDown/BBDownApiServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ public void SetUpServer()
{
options.SerializerOptions.TypeInfoResolver = JsonTypeInfoResolver.Combine(options.SerializerOptions.TypeInfoResolver, AppJsonSerializerContext.Default);
});
builder.Services.AddCors((options) =>
{
options.AddPolicy("AllowAnyOrigin",
policy =>
{
policy.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
app = builder.Build();
app.UseCors("AllowAnyOrigin");
var taskStatusApi = app.MapGroup("/get-tasks");
taskStatusApi.MapGet("/", handler: () => Results.Json(new DownloadTaskCollection(runningTasks, finishedTasks), AppJsonSerializerContext.Default.DownloadTaskCollection));
taskStatusApi.MapGet("/running", handler: () => Results.Json(runningTasks, AppJsonSerializerContext.Default.ListDownloadTask));
Expand Down

0 comments on commit 5d6623c

Please sign in to comment.