CORS Enable Headers
See original GitHub issueHi, my implementation was failing due to missing headers in response. File uploads were not resuming. I inspected the http://tus.io/demo.html network requests and noticed this header, which was missing in my node server’s responses:
'Access-Control-Expose-Headers' : 'Upload-Offset, Location, Upload-Length, Tus-Version, Tus-Resumable, Tus-Max-Size, Tus-Extension, Upload-Metadata'
I examined the node.js library code a little bit, and discovered that on Server.js file you are controlling CORS with the following lines :
if (req.headers.origin) {
res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
}
I believe it should also set the “Access-Control-Expose-Headers” header too. So i changed to following piece of code and it worked :
if (req.headers.origin) {
res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
res.setHeader('Access-Control-Expose-Headers' , 'Upload-Offset, Location, Upload-Length, Tus-Version, Tus-Resumable, Tus-Max-Size, Tus-Extension, Upload-Metadata');
}
Is there a better way to achieve CORS, or is this the way to do it? Thank you.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Cross-Origin Resource Sharing (CORS) - MDN Web Docs
Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, ...
Read more >CORS Enabled - W3C Wiki
Open Internet Information Service (IIS) Manager · Right click the site you want to enable CORS for and go to Properties · Change...
Read more >How does the 'Access-Control-Allow-Origin' header work?
Wikipedia: The CORS standard describes new HTTP headers which provide browsers and servers a way to request remote URLs only when they have...
Read more >CORS and the Access-Control-Allow-Origin response header
The CORS specification identifies a collection of protocol headers of which Access-Control-Allow-Origin is the most significant. This header is returned by a ...
Read more >How to Enable CORS Headers for Your Application
How to Enable CORS Headers · Step 1: Go to Applications. Log in to your account and click the Applications in the top...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Since there was no Location info, the URL for PATCH was null. That was the actual error. Now everything seems to be OK, thank you!
@krampampuli thanks for your help.
Location
is added in tus-node-server@0.1.3.Not sure I’m following how
PATCH
isn’t allowed, since it is included in theAccess-Control-Allow-Methods
ofOPTIONS
request. Would you mind opening up a separate ticket with detailed steps to replicate?