@@ -5,31 +5,24 @@ import { Application } from "express";
55import { Service } from "../config" ;
66
77export const applySecurityMiddleware = ( app : Application ) => {
8- // Add request logging
9- // app.use((req: Request, res: Response, next: NextFunction) => {
10- // console.log(`[${new Date().toISOString()}] ${req.method} ${req.url}`);
11- // console.log('Headers:', JSON.stringify(req.headers));
12- // next();
13- // });
14-
15- // app.use(helmet({
16- // crossOriginResourcePolicy: { policy: "cross-origin" },
17- // }));
8+ // Apply Helmet with CORS-friendly settings
9+ app . use ( helmet ( {
10+ crossOriginResourcePolicy : { policy : "cross-origin" } ,
11+ } ) ) ;
1812
19- // console.log('Setting up CORS with client URL:', Service.CLIENT_URL);
20-
13+ // Configure CORS properly
2114 app . use ( cors ( {
22- origin : "*" ,
15+ origin : [ Service . CLIENT_URL , "https://welearning.online" ] ,
2316 methods : [ "GET" , "POST" , "HEAD" , "PUT" , "PATCH" , "DELETE" , "OPTIONS" ] ,
2417 credentials : true ,
25- // allowedHeaders: ['Content-Type', 'Authorization', 'Cookie', 'Range', 'Accept'],
26- // exposedHeaders: ['Content-Disposition', 'Content-Range', 'Accept-Ranges', 'Content-Length', 'Content-Type']
18+ allowedHeaders : [ 'Content-Type' , 'Authorization' , 'Cookie' , 'Range' , 'Accept' , 'X-Requested-With '] ,
19+ exposedHeaders : [ 'Content-Disposition' , 'Content-Range' , 'Accept-Ranges' , 'Content-Length' , 'Content-Type' ]
2720 } ) ) ;
28-
21+
22+ // Apply rate limiter if needed
2923 const limiter = rateLimit ( {
30- windowMs : 15 * 60 * 1000 , // 15 minutes (fixed from 15 * 16 * 1000 which was incorrect)
24+ windowMs : 15 * 60 * 1000 , // 15 minutes
3125 max : 100
3226 } ) ;
33-
3427 app . use ( limiter ) ;
3528} ;
0 commit comments