Configure Web-Grpc and CORS
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Grpc.AspNetCore" Version="2.71.0" />
|
||||
<PackageReference Include="Grpc.AspNetCore.Web" Version="2.71.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.71.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
||||
@@ -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<AobaRpcService>();
|
||||
app.MapGrpcService<AobaRpcService>()
|
||||
.RequireCors("AllowAll");
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,14 +19,16 @@ public static class ProtoExtensions
|
||||
|
||||
public static Pagination ToPagination<T>(this PagedResult<T> 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)
|
||||
|
||||
Reference in New Issue
Block a user