From 5d6623cdb8f10468fca65c48510b7ea413469b33 Mon Sep 17 00:00:00 2001 From: gnattu Date: Wed, 25 Oct 2023 12:14:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0CORS=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E6=B5=8F=E8=A7=88=E5=99=A8=E8=B7=A8=E5=9F=9F?= =?UTF-8?q?=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BBDown/BBDownApiServer.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/BBDown/BBDownApiServer.cs b/BBDown/BBDownApiServer.cs index 80cfeb7f1..b5e786048 100644 --- a/BBDown/BBDownApiServer.cs +++ b/BBDown/BBDownApiServer.cs @@ -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));