Skip to content

Commit

Permalink
fix: allow cors interceptor
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Oct 7, 2024
1 parent 384e2e2 commit fa207ea
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
ExecutionContext,
NestInterceptor,
} from '@nestjs/common'
import type { FastifyBizRequest } from '~/transformers/get-req.transformer'
import type { FastifyReply } from 'fastify'

import { RequestMethod } from '@nestjs/common'
Expand All @@ -11,6 +12,7 @@ export class AllowAllCorsInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler<any>) {
const handle = next.handle()
const response: FastifyReply<any> = context.switchToHttp().getResponse()
const request: FastifyBizRequest = context.switchToHttp().getRequest()
const allowedMethods = [
RequestMethod.GET,
RequestMethod.HEAD,
Expand All @@ -30,8 +32,9 @@ export class AllowAllCorsInterceptor implements NestInterceptor {
'Expires',
'Content-Type',
]
const host = request.headers.origin
response.headers({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Origin': host,
'Access-Control-Allow-Headers': allowedHeaders.join(','),
'Access-Control-Allow-Methods': allowedMethods.join(','),
'Access-Control-Max-Age': '86400',
Expand Down

0 comments on commit fa207ea

Please sign in to comment.