Skip to content

Commit

Permalink
fix: bypass OPTIONS
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed May 7, 2024
1 parent 7c56488 commit 1a85d54
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apps/core/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export async function bootstrap() {
callback(null, allow)
},
credentials: true,
preflightContinue: false,
optionsSuccessStatus: 204,
}
: undefined,
)
Expand Down
2 changes: 2 additions & 0 deletions apps/core/src/common/filters/any-exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class AllExceptionsFilter implements ExceptionFilter {
const response = ctx.getResponse<FastifyReply>()
const request = ctx.getRequest<FastifyRequest>()

if (request.method === 'OPTIONS') return response.status(204).send()
const ip = getIp(request)

const status =
Expand All @@ -86,6 +87,7 @@ export class AllExceptionsFilter implements ExceptionFilter {
''
const url = request.raw?.url || request.url || 'Unknown URL'
if (status === HttpStatus.TOO_MANY_REQUESTS) {
this.logger.warn(`IP: ${ip} 鐤戜技閬埌鏀诲嚮 Path: ${decodeURI(url)}`)
this.barkService.throttlePush({
title: '鐤戜技閬埌鏀诲嚮',
body: `IP: ${ip} Path: ${decodeURI(url)}`,
Expand Down
3 changes: 0 additions & 3 deletions apps/core/src/modules/serverless/serverless.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ export class ServerlessController {
@Request() req: FastifyRequest,
@Response() reply: FastifyReply,
) {
if (req.method === 'OPTIONS') {
return reply.send()
}
return this.runServerlessFunction(param, isAuthenticated, req, reply)
}

Expand Down

0 comments on commit 1a85d54

Please sign in to comment.