@@ -92,9 +92,29 @@ const corsProxyOptions = {
9292 console . log ( chalk . green ( 'Original response headers:' ) , proxyRes . headers ) ;
9393
9494 // Adjust response headers based on the original request
95- proxyRes . headers [ 'Access-Control-Allow-Origin' ] = req . headers [ 'origin' ] || '*' ;
96- proxyRes . headers [ 'Access-Control-Allow-Methods' ] = req . headers [ 'access-control-request-method' ] || 'GET,POST,PUT,PATCH,DELETE,OPTIONS' ;
97- proxyRes . headers [ 'Access-Control-Allow-Headers' ] = req . headers [ 'access-control-request-headers' ] || 'Origin, Content-Type, Accept, Authorization' ;
95+ const origin = req . headers [ 'origin' ] || '*' ;
96+ const allowMethods = 'GET,POST,PUT,PATCH,DELETE,OPTIONS' ;
97+ const allowHeaders = 'Accept, Authorization, Content-Length, Content-Type, Depth, DPoP, If-None-Match, Link, Location, On-Behalf-Of, Origin, Slug, WebID-TLS, X-Requested-With' ;
98+ const exposeHeaders = 'Content-disposition,Content-Type,Access-Control-Allow-Headers,Access-Control-Allow-Methods,Access-Control-Allow-Origin,Allow,Accept-Patch,Accept-Post,Authorization,Content-Length,ETag,Last-Modified,Link,Location,Updates-Via,User,Vary,WAC-Allow,WWW-Authenticate' ;
99+
100+ // Set headers in both uppercase and lowercase formats for maximum compatibility
101+ proxyRes . headers [ 'Access-Control-Allow-Origin' ] = origin ;
102+ proxyRes . headers [ 'access-control-allow-origin' ] = origin ;
103+
104+ proxyRes . headers [ 'Access-Control-Allow-Methods' ] = allowMethods ;
105+ proxyRes . headers [ 'access-control-allow-methods' ] = allowMethods ;
106+
107+ proxyRes . headers [ 'Access-Control-Allow-Headers' ] = allowHeaders ;
108+ proxyRes . headers [ 'access-control-allow-headers' ] = allowHeaders ;
109+
110+ proxyRes . headers [ 'Access-Control-Allow-Credentials' ] = 'true' ;
111+ proxyRes . headers [ 'access-control-allow-credentials' ] = 'true' ;
112+
113+ proxyRes . headers [ 'Access-Control-Max-Age' ] = '86400' ;
114+ proxyRes . headers [ 'access-control-max-age' ] = '86400' ;
115+
116+ proxyRes . headers [ 'Access-Control-Expose-Headers' ] = exposeHeaders ;
117+ proxyRes . headers [ 'access-control-expose-headers' ] = exposeHeaders ;
98118
99119 // Log the modified response headers
100120 console . log ( chalk . green ( 'Modified response headers:' ) , proxyRes . headers ) ;
@@ -108,11 +128,30 @@ const corsProxyOptions = {
108128// Handle OPTIONS requests (preflight) for all routes without proxying
109129app . options ( '*' , ( req , res ) => {
110130 console . log ( chalk . yellow ( 'Received OPTIONS request (preflight) for:' ) , chalk . yellowBright ( req . originalUrl ) ) ;
111- res . header ( 'Access-Control-Allow-Origin' , req . headers [ 'origin' ] || '*' ) ;
112- res . header ( 'Access-Control-Allow-Methods' , 'GET,POST,PUT,PATCH,DELETE,OPTIONS' ) ;
113- res . header ( 'Access-Control-Allow-Headers' , 'X-Requested-With,Content-Type,Accept,Origin,Last-Modified,Authorization' ) ;
131+ const origin = req . headers [ 'origin' ] || '*' ;
132+ const allowMethods = 'GET,POST,PUT,PATCH,DELETE,OPTIONS' ;
133+ const allowHeaders = 'Accept, Authorization, Content-Length, Content-Type, Depth, DPoP, If-None-Match, Link, Location, On-Behalf-Of, Origin, Slug, WebID-TLS, X-Requested-With' ;
134+ const exposeHeaders = 'Content-disposition,Content-Type,Access-Control-Allow-Headers,Access-Control-Allow-Methods,Access-Control-Allow-Origin,Allow,Accept-Patch,Accept-Post,Authorization,Content-Length,ETag,Last-Modified,Link,Location,Updates-Via,User,Vary,WAC-Allow,WWW-Authenticate' ;
135+
136+ // Set headers in both uppercase and lowercase formats for maximum compatibility
137+ res . header ( 'Access-Control-Allow-Origin' , origin ) ;
138+ res . header ( 'access-control-allow-origin' , origin ) ;
139+
140+ res . header ( 'Access-Control-Allow-Methods' , allowMethods ) ;
141+ res . header ( 'access-control-allow-methods' , allowMethods ) ;
142+
143+ res . header ( 'Access-Control-Allow-Headers' , allowHeaders ) ;
144+ res . header ( 'access-control-allow-headers' , allowHeaders ) ;
145+
114146 res . header ( 'Access-Control-Allow-Credentials' , 'true' ) ;
115- res . header ( 'Access-Control-Max-Age' , '86400' ) ; // 24 hours
147+ res . header ( 'access-control-allow-credentials' , 'true' ) ;
148+
149+ res . header ( 'Access-Control-Max-Age' , '86400' ) ;
150+ res . header ( 'access-control-max-age' , '86400' ) ;
151+
152+ res . header ( 'Access-Control-Expose-Headers' , exposeHeaders ) ;
153+ res . header ( 'access-control-expose-headers' , exposeHeaders ) ;
154+
116155 res . sendStatus ( 200 ) ;
117156} ) ;
118157
0 commit comments