This is the error I'm getting :
Access to XMLHttpRequest at has been blocked by CORS policy: Response to preflight request
doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
This is my cloud function:
...
app.use(cors({
origin: true,
}))
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.post('/submit', async (req, clientRes) => {
...
}
exports.app = functions.region('europe-west2').runWith({timeoutSeconds: 540, memory: '2GB'}).https.onRequest(app);
This is the post request I'm making from the client side:
axios.post('/submit', body, {headers: {
// 'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
}});
I tried setting the Access-Control-Allow-Origin: '*'
, Access-Control-Allow-Origin: mydomain.com
and also Access-Control-Allow-Origin: cloudFunctionDomain.net
but it is still not working.
Help would be very much appreciated.