init
This commit is contained in:
32
DouyinApi.Extensions/Middlewares/IpLimitMiddleware.cs
Normal file
32
DouyinApi.Extensions/Middlewares/IpLimitMiddleware.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using AspNetCoreRateLimit;
|
||||
using DouyinApi.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using System;
|
||||
using Serilog;
|
||||
|
||||
namespace DouyinApi.Extensions.Middlewares
|
||||
{
|
||||
/// <summary>
|
||||
/// ip 限流
|
||||
/// </summary>
|
||||
public static class IpLimitMiddleware
|
||||
{
|
||||
public static void UseIpLimitMiddle(this IApplicationBuilder app)
|
||||
{
|
||||
if (app == null) throw new ArgumentNullException(nameof(app));
|
||||
|
||||
try
|
||||
{
|
||||
if (AppSettings.app("Middleware", "IpRateLimit", "Enabled").ObjToBool())
|
||||
{
|
||||
app.UseIpRateLimiting();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error($"Error occured limiting ip rate.\n{e.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user