@@ -8,12 +8,15 @@ dotenv.config();
8
8
9
9
const app = express ( ) ;
10
10
11
+ // Trust proxy settings for proper client IP handling
12
+ app . set ( 'trust proxy' , true ) ;
13
+
11
14
// Middleware
12
15
app . use ( express . json ( ) ) ;
13
16
app . use ( cors ( {
14
17
origin : config . corsOrigin ,
15
18
methods : [ 'GET' , 'POST' , 'PUT' , 'DELETE' , 'OPTIONS' ] ,
16
- allowedHeaders : [ 'Content-Type' , 'x-api-key' , 'Authorization' , 'X-Requested-With' ] ,
19
+ allowedHeaders : [ 'Content-Type' , 'x-api-key' , 'Authorization' , 'X-Requested-With' , 'X-Forwarded-For' , 'X-Real-IP' ] ,
17
20
exposedHeaders : [ 'Content-Length' , 'Content-Type' ] ,
18
21
credentials : true ,
19
22
maxAge : 86400 ,
@@ -22,9 +25,16 @@ app.use(cors({
22
25
23
26
// Add headers middleware
24
27
const headersMiddleware : RequestHandler = ( req , res , next ) => {
28
+ // Get the actual client IP when behind a proxy
29
+ const clientIP = req . headers [ 'x-forwarded-for' ] || req . headers [ 'x-real-ip' ] || req . ip ;
30
+
25
31
res . header ( 'Access-Control-Allow-Origin' , '*' ) ;
26
32
res . header ( 'Access-Control-Allow-Methods' , 'GET, POST, PUT, DELETE, OPTIONS' ) ;
27
- res . header ( 'Access-Control-Allow-Headers' , 'Content-Type, x-api-key, Authorization, X-Requested-With' ) ;
33
+ res . header ( 'Access-Control-Allow-Headers' , 'Content-Type, x-api-key, Authorization, X-Requested-With, X-Forwarded-For, X-Real-IP' ) ;
34
+
35
+ // Set Cache-Control to no-cache for streaming responses
36
+ res . header ( 'Cache-Control' , 'no-cache, no-transform' ) ;
37
+
28
38
if ( req . method === 'OPTIONS' ) {
29
39
res . status ( 204 ) . end ( ) ;
30
40
return ;
0 commit comments