Added frontend and working fetching.
This commit is contained in:
+34
-9
@@ -1,10 +1,11 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using MessagePack;
|
||||
using Microsoft.AspNetCore.Cors.Infrastructure;
|
||||
using AspNetCoreRateLimit;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Models.Model.External;
|
||||
using NetMQ;
|
||||
using NetMQ.Sockets;
|
||||
const string myAllowSpecificOrigins = "_myAllowSpecificOrigins";
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateSlimBuilder(args);
|
||||
|
||||
@@ -15,16 +16,40 @@ builder.Services.ConfigureHttpJsonOptions(options =>
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("CorsPolicy", x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().Build());
|
||||
options.AddPolicy(name: myAllowSpecificOrigins, x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
|
||||
});
|
||||
|
||||
// Add memory cache and rate limiting services
|
||||
builder.Services.AddMemoryCache();
|
||||
builder.Services.Configure<IpRateLimitOptions>(options =>
|
||||
{
|
||||
options.GeneralRules =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Endpoint = "*", // Apply to all endpoints
|
||||
Period = "10s", // Rate limiting window of 10 second
|
||||
Limit = 5 // Maximum 5 requests per 10 seconds
|
||||
}
|
||||
];
|
||||
});
|
||||
|
||||
builder.Services.AddInMemoryRateLimiting();
|
||||
builder.Services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
|
||||
|
||||
WebApplication app = builder.Build();
|
||||
|
||||
app.UseCors();
|
||||
app.UseForwardedHeaders(new()
|
||||
{
|
||||
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
||||
});
|
||||
|
||||
|
||||
app.UseIpRateLimiting(); // Apply IP-based rate limiting middleware
|
||||
|
||||
app.UseCors(myAllowSpecificOrigins);
|
||||
|
||||
RouteGroupBuilder progressApi = app.MapGroup("/progress");
|
||||
progressApi.AllowAnonymous();
|
||||
progressApi.DisableAntiforgery();
|
||||
progressApi.MapGet("/", () =>
|
||||
{
|
||||
CommunicationObject communicationObject = new()
|
||||
@@ -43,8 +68,8 @@ progressApi.MapGet("/", () =>
|
||||
return JsonSerializer.Deserialize<ScanningStatus>(msg);
|
||||
});
|
||||
|
||||
/*
|
||||
RouteGroupBuilder searchApi = app.MapGroup("/search");
|
||||
progressApi.AllowAnonymous();
|
||||
searchApi.MapGet("/{term}", (string term) =>
|
||||
{
|
||||
CommunicationObject communicationObject = new();
|
||||
@@ -61,11 +86,11 @@ searchApi.MapGet("/{term}", (string term) =>
|
||||
|
||||
return JsonSerializer.Deserialize<SearchResults?>(msg);
|
||||
});
|
||||
|
||||
*/
|
||||
app.Run();
|
||||
|
||||
[JsonSerializable(typeof(ScanningStatus))]
|
||||
[JsonSerializable(typeof(SearchResults))]
|
||||
//[JsonSerializable(typeof(SearchResults))]
|
||||
[JsonSerializable(typeof(CommunicationObject))]
|
||||
internal partial class AppJsonSerializerContext : JsonSerializerContext
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
|
||||
<PackageReference Include="NetMQ" Version="4.0.1.13" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Default": "Warning",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user