mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-06 11:59:51 +08:00
fix(server): relax the rate limits (#4092)
This commit is contained in:
@@ -91,15 +91,13 @@ jobs:
|
|||||||
|
|
||||||
- name: Generate prisma client
|
- name: Generate prisma client
|
||||||
run: |
|
run: |
|
||||||
yarn exec prisma generate
|
yarn workspace @affine/server exec prisma generate
|
||||||
yarn exec prisma db push
|
yarn workspace @affine/server exec prisma db push
|
||||||
working-directory: apps/server
|
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: postgresql://affine:affine@localhost:5432/affine
|
DATABASE_URL: postgresql://affine:affine@localhost:5432/affine
|
||||||
|
|
||||||
- name: Run init-db script
|
- name: Run init-db script
|
||||||
run: yarn exec ts-node-esm ./scripts/init-db.ts
|
run: yarn workspace @affine/server exec ts-node-esm ./scripts/init-db.ts
|
||||||
working-directory: apps/server
|
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: postgresql://affine:affine@localhost:5432/affine
|
DATABASE_URL: postgresql://affine:affine@localhost:5432/affine
|
||||||
|
|
||||||
@@ -110,8 +108,7 @@ jobs:
|
|||||||
path: ./apps/server
|
path: ./apps/server
|
||||||
|
|
||||||
- name: Run server tests
|
- name: Run server tests
|
||||||
run: yarn test:coverage
|
run: yarn workspace @affine/server test:coverage
|
||||||
working-directory: apps/server
|
|
||||||
env:
|
env:
|
||||||
CARGO_TARGET_DIR: '${{ github.workspace }}/target'
|
CARGO_TARGET_DIR: '${{ github.workspace }}/target'
|
||||||
DATABASE_URL: postgresql://affine:affine@localhost:5432/affine
|
DATABASE_URL: postgresql://affine:affine@localhost:5432/affine
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export class NextAuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(CloudThrottlerGuard)
|
@UseGuards(CloudThrottlerGuard)
|
||||||
@Throttle(20, 60)
|
@Throttle(60, 60)
|
||||||
@All('*')
|
@All('*')
|
||||||
async auth(
|
async auth(
|
||||||
@Req() req: Request,
|
@Req() req: Request,
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import { UsersModule } from './users';
|
|||||||
import { WorkspaceModule } from './workspaces';
|
import { WorkspaceModule } from './workspaces';
|
||||||
|
|
||||||
const { SERVER_FLAVOR } = process.env;
|
const { SERVER_FLAVOR } = process.env;
|
||||||
const { NODE_ENV } = process.env;
|
|
||||||
|
|
||||||
const BusinessModules: (Type | DynamicModule)[] = [];
|
const BusinessModules: (Type | DynamicModule)[] = [];
|
||||||
|
|
||||||
@@ -40,13 +39,11 @@ switch (SERVER_FLAVOR) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Providers: Provider[] = [];
|
const Providers: Provider[] = [
|
||||||
|
{
|
||||||
if (NODE_ENV !== 'test') {
|
|
||||||
Providers.push({
|
|
||||||
provide: APP_FILTER,
|
provide: APP_FILTER,
|
||||||
useClass: ExceptionLogger,
|
useClass: ExceptionLogger,
|
||||||
});
|
},
|
||||||
}
|
];
|
||||||
|
|
||||||
export { BusinessModules, Providers };
|
export { BusinessModules, Providers };
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { AppModule } from '../app';
|
|||||||
|
|
||||||
const gql = '/graphql';
|
const gql = '/graphql';
|
||||||
|
|
||||||
describe('AppModule', () => {
|
describe('AppModule', async () => {
|
||||||
let app: INestApplication;
|
let app: INestApplication;
|
||||||
|
|
||||||
// cleanup database before each test
|
// cleanup database before each test
|
||||||
@@ -54,7 +54,7 @@ describe('AppModule', () => {
|
|||||||
await app.close();
|
await app.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should init app', async () => {
|
await test('should init app', async () => {
|
||||||
ok(typeof app === 'object');
|
ok(typeof app === 'object');
|
||||||
await request(app.getHttpServer())
|
await request(app.getHttpServer())
|
||||||
.post(gql)
|
.post(gql)
|
||||||
@@ -85,7 +85,7 @@ describe('AppModule', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should find default user', async () => {
|
await test('should find default user', async () => {
|
||||||
const { token } = await createToken(app);
|
const { token } = await createToken(app);
|
||||||
await request(app.getHttpServer())
|
await request(app.getHttpServer())
|
||||||
.post(gql)
|
.post(gql)
|
||||||
@@ -106,7 +106,7 @@ describe('AppModule', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should be able to upload avatar', async () => {
|
await test('should be able to upload avatar', async () => {
|
||||||
const { token, id } = await createToken(app);
|
const { token, id } = await createToken(app);
|
||||||
const png = await Transformer.fromRgbaPixels(
|
const png = await Transformer.fromRgbaPixels(
|
||||||
Buffer.alloc(400 * 400 * 4).fill(255),
|
Buffer.alloc(400 * 400 * 4).fill(255),
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ describe('Workspace Module', () => {
|
|||||||
ok(user.email === 'u1@affine.pro', 'user.email is not valid');
|
ok(user.email === 'u1@affine.pro', 'user.email is not valid');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be throttled at call signUp', async () => {
|
it.skip('should be throttled at call signUp', async () => {
|
||||||
let token = '';
|
let token = '';
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
token = (await signUp(app, `u${i}`, `u${i}@affine.pro`, `${i}`)).token
|
token = (await signUp(app, `u${i}`, `u${i}@affine.pro`, `${i}`)).token
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ import { getRequestResponseFromContext } from './utils/nestjs';
|
|||||||
const options: ThrottlerModuleOptions = {
|
const options: ThrottlerModuleOptions = {
|
||||||
ttl: config.rateLimiter.ttl,
|
ttl: config.rateLimiter.ttl,
|
||||||
limit: config.rateLimiter.limit,
|
limit: config.rateLimiter.limit,
|
||||||
|
skipIf: () => {
|
||||||
|
return !config.node.prod || config.affine.canary;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
if (config.redis.enabled) {
|
if (config.redis.enabled) {
|
||||||
new Logger(RateLimiterModule.name).log('Use Redis');
|
new Logger(RateLimiterModule.name).log('Use Redis');
|
||||||
|
|||||||
Reference in New Issue
Block a user