mirror of https://github.com/fantasticit/think.git
server: add rateLimit
This commit is contained in:
parent
04ae4949e9
commit
cd19310974
|
@ -20,6 +20,9 @@ server:
|
||||||
collaborationPort: 5003
|
collaborationPort: 5003
|
||||||
maxDocumentVersion: 20 # 最大版本记录数
|
maxDocumentVersion: 20 # 最大版本记录数
|
||||||
logRetainDays: 3 # 日志保留天数,比如只保留近三天日志
|
logRetainDays: 3 # 日志保留天数,比如只保留近三天日志
|
||||||
|
enableRateLimit: true # 是否限流
|
||||||
|
rateLimitWindowMs: 60000 # 限流时间
|
||||||
|
rateLimitMax: 1000 # 单位限流时间内单个 up 最大访问数量
|
||||||
|
|
||||||
# 数据库配置
|
# 数据库配置
|
||||||
db:
|
db:
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { HttpResponseTransformInterceptor } from '@transforms/http-response.tran
|
||||||
import * as compression from 'compression';
|
import * as compression from 'compression';
|
||||||
import * as cookieParser from 'cookie-parser';
|
import * as cookieParser from 'cookie-parser';
|
||||||
import * as express from 'express';
|
import * as express from 'express';
|
||||||
|
import rateLimit from 'express-rate-limit';
|
||||||
import helmet from 'helmet';
|
import helmet from 'helmet';
|
||||||
|
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
|
@ -22,6 +23,14 @@ async function bootstrap() {
|
||||||
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
|
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
|
||||||
credentials: true,
|
credentials: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
config.get('server.enableRateLimit') &&
|
||||||
|
app.use(
|
||||||
|
rateLimit({
|
||||||
|
windowMs: config.get('server.rateLimitWindowMs'),
|
||||||
|
max: config.get('server.rateLimitMax'),
|
||||||
|
})
|
||||||
|
);
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
app.use(compression());
|
app.use(compression());
|
||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
|
|
Loading…
Reference in New Issue