Skip to content

Commit

Permalink
fix(cors): cors is true for any incoming request on developer server
Browse files Browse the repository at this point in the history
quick fix to remain developer process, need implement logic for developer and production server in
future
  • Loading branch information
quannhg committed Nov 1, 2023
1 parent 6416e91 commit 0dfda11
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Server.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import fastify, { FastifyInstance } from 'fastify';
import type { FastifyCookieOptions } from '@fastify/cookie';
import { CORS_WHITE_LIST, customErrorHandler, envs, loggerConfig, swaggerConfig, swaggerUIConfig } from '@configs';
import { customErrorHandler, envs, loggerConfig, swaggerConfig, swaggerUIConfig } from '@configs';
import { apiPlugin, authPlugin } from './routes';
import { checkRoles } from '@hooks';

export function createServer(config: ServerConfig): FastifyInstance {
const app = fastify({ logger: loggerConfig[envs.NODE_ENV], ajv: { plugins: [require('@fastify/multipart').ajvFilePlugin] } });

app.register(import('@fastify/cors'), {
origin: CORS_WHITE_LIST,
// TODO: When come to production, change the logic of code to only set origin true on developer server
// origin: CORS_WHITE_LIST,
origin: true,
credentials: true
});
app.register(import('@fastify/sensible'));
Expand Down

0 comments on commit 0dfda11

Please sign in to comment.