mr.nobody4704Original post
Web Developer
I am trying to add custom cors headers in my cloud function because I'm not able to access it with other domains. But im not able to add them with
res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Methods', 'GET, POST'); res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
Summary
To set CORS headers in your Node.js cloud functions, add the headers using res.set() in your function code. Make sure the headers are set before sending the response.
Example:
```javascript
res.set({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST',
'Access-Control-Allow-Headers': 'Content-Type, Authorization'
});
```
Ensure the headers are set correctly and the response is sent after setting them. This should allow access from other domains.