Configure Web-Grpc and CORS
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Grpc.AspNetCore" Version="2.71.0" />
|
<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">
|
<PackageReference Include="Grpc.Tools" Version="2.71.0">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
|||||||
@@ -35,6 +35,17 @@ var validationParams = new TokenValidationParameters
|
|||||||
ClockSkew = TimeSpan.FromMinutes(1),
|
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 =>
|
builder.Services.AddAuthentication(options =>
|
||||||
{
|
{
|
||||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
@@ -82,10 +93,11 @@ if (!app.Environment.IsDevelopment())
|
|||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true });
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
|
app.UseCors();
|
||||||
|
|
||||||
|
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
@@ -94,7 +106,8 @@ app.UseAuthorization();
|
|||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
app.MapObserability();
|
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)
|
public static Pagination ToPagination<T>(this PagedResult<T> result)
|
||||||
{
|
{
|
||||||
return new Pagination()
|
var p =new Pagination()
|
||||||
{
|
{
|
||||||
Page = result.Page,
|
Page = result.Page,
|
||||||
PageSize = result.PageSize,
|
PageSize = result.PageSize,
|
||||||
TotalItems = result.TotalItems,
|
TotalItems = result.TotalItems,
|
||||||
TotalPages = result.TotalPages,
|
TotalPages = result.TotalPages,
|
||||||
Query = result.Query,
|
|
||||||
};
|
};
|
||||||
|
if(result.Query != null)
|
||||||
|
p.Query = result.Query;
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MediaResponse ToResponse(this Media? media)
|
public static MediaResponse ToResponse(this Media? media)
|
||||||
|
|||||||
Reference in New Issue
Block a user