diff --git a/AobaServer/AobaServer.csproj b/AobaServer/AobaServer.csproj index ffcabe8..94af97f 100644 --- a/AobaServer/AobaServer.csproj +++ b/AobaServer/AobaServer.csproj @@ -10,6 +10,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/AobaServer/Program.cs b/AobaServer/Program.cs index 1c4a5d3..49c4b19 100644 --- a/AobaServer/Program.cs +++ b/AobaServer/Program.cs @@ -35,6 +35,17 @@ var validationParams = new TokenValidationParameters ClockSkew = TimeSpan.FromMinutes(1), }; +builder.Services.AddCors(o => +{ + o.AddPolicy("AllowAll", p => + { + p.AllowAnyOrigin(); + p.AllowAnyMethod(); + p.AllowAnyHeader(); + //p.WithOrigins("http://127.0.0.1:8080", "https://aoba.app"); + }); +}); + builder.Services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; @@ -82,10 +93,11 @@ if (!app.Environment.IsDevelopment()) app.UseHsts(); } - +app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true }); app.UseHttpsRedirection(); app.UseRouting(); +app.UseCors(); app.UseAuthentication(); @@ -94,7 +106,8 @@ app.UseAuthorization(); app.MapControllers(); app.MapObserability(); -app.MapGrpcService(); +app.MapGrpcService() + .RequireCors("AllowAll"); diff --git a/AobaServer/Utils/ProtoExtensions.cs b/AobaServer/Utils/ProtoExtensions.cs index ef18910..e6013ba 100644 --- a/AobaServer/Utils/ProtoExtensions.cs +++ b/AobaServer/Utils/ProtoExtensions.cs @@ -19,14 +19,16 @@ public static class ProtoExtensions public static Pagination ToPagination(this PagedResult result) { - return new Pagination() + var p =new Pagination() { Page = result.Page, PageSize = result.PageSize, TotalItems = result.TotalItems, TotalPages = result.TotalPages, - Query = result.Query, }; + if(result.Query != null) + p.Query = result.Query; + return p; } public static MediaResponse ToResponse(this Media? media)