Compare commits
2 Commits
dba9b516b8
...
f15bf4dfe6
Author | SHA1 | Date | |
---|---|---|---|
f15bf4dfe6 | |||
e3bcdfa4e6 |
@@ -13,7 +13,10 @@ var configuration = builder.Configuration;
|
||||
string? preinstalledJwtToken = configuration["TOKEN"];
|
||||
string? tgChatId = configuration["TG_CHAT_ID"];
|
||||
string? tgToken = configuration["TG_TOKEN"];
|
||||
string updateJwtCron = configuration["UPDATE_JWT_CRON"] ?? "0 4 * ? * *";
|
||||
string updateJwtCron = configuration["UPDATE_JWT_CRON"] ?? "0 0 4 ? * *";
|
||||
|
||||
int permitLimit = int.TryParse(configuration["PERMIT_LIMIT"], out var parsedPermitLimit) ? parsedPermitLimit : 40;
|
||||
int timeLimit = int.TryParse(configuration["TIME_LIMIT"], out var parsedTimeLimit) ? parsedTimeLimit : 10;
|
||||
|
||||
// создать папку data если не существует
|
||||
var dataDirectory = Path.Combine(AppContext.BaseDirectory, "data");
|
||||
@@ -82,14 +85,14 @@ builder.Services.AddRateLimiter(options =>
|
||||
: (httpContext.Connection.RemoteIpAddress?.ToString() ?? "unknown"),
|
||||
factory: _ => new FixedWindowRateLimiterOptions
|
||||
{
|
||||
PermitLimit = 40,
|
||||
Window = TimeSpan.FromSeconds(10)
|
||||
PermitLimit = permitLimit,
|
||||
Window = TimeSpan.FromSeconds(timeLimit)
|
||||
}));
|
||||
|
||||
options.OnRejected = async (context, cancellationToken) =>
|
||||
{
|
||||
context.HttpContext.Response.StatusCode = StatusCodes.Status429TooManyRequests;
|
||||
context.HttpContext.Response.Headers["Retry-After"] = "60";
|
||||
context.HttpContext.Response.Headers["Retry-After"] = timeLimit.ToString();
|
||||
|
||||
await context.HttpContext.Response.WriteAsync("Rate limit exceeded. Please try again later.",
|
||||
cancellationToken);
|
||||
|
Reference in New Issue
Block a user