@@ -7,7 +7,7 @@ import compression from 'compression';
77import cookieParser from 'cookie-parser' ;
88
99import { AppModule } from './app/app.module' ;
10- import { FRONTEND_URL , PORT } from './config/constants' ;
10+ import { PORT } from './config/constants' ;
1111import { DEFAULT_PORT } from './constants' ;
1212
1313async function bootstrap ( ) {
@@ -19,13 +19,34 @@ async function bootstrap() {
1919 const globalPrefix = 'api/v1' ;
2020 app . setGlobalPrefix ( globalPrefix ) ;
2121
22- const origin = configService ?. get < string > ( FRONTEND_URL ) ;
23-
2422 app . use ( cookieParser ( ) ) ;
2523 app . use ( helmet ( ) ) ;
26- // TODO: we need to set frontend url and update it in railway
2724 app . enableCors ( {
28- origin : [ origin || '*' , 'http://localhost:3001' , 'http://localhost:5173' ] ,
25+ origin : ( origin , callback ) => {
26+ if ( ! origin ) {
27+ return callback ( null , true ) ;
28+ }
29+
30+ const allowedOrigins = [
31+ 'http://localhost:5173' ,
32+ 'http://localhost:3001' ,
33+ 'https://fit-tracker-corp.netlify.app' ,
34+ ] ;
35+
36+ if ( allowedOrigins . includes ( origin ) ) {
37+ return callback ( null , true ) ;
38+ }
39+
40+ const isNetlifyPreview =
41+ / ^ h t t p s : \/ \/ d e p l o y - p r e v i e w - \d + - - f i t - t r a c k e r - c o r p \. n e t l i f y \. a p p $ / . test (
42+ origin ,
43+ ) ;
44+
45+ if ( isNetlifyPreview ) {
46+ return callback ( null , true ) ;
47+ }
48+ callback ( new Error ( 'Not allowed by CORS' ) ) ;
49+ } ,
2950 methods : 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS' ,
3051 credentials : true ,
3152 } ) ;
0 commit comments