I am facing an issue with my Firebase cloud function endpoint. I have a setup where it forwards PUT requests to another API endpoint. I have configured the following Access-Control-Allow-
headers:
// src/middlewares/enableCORS.ts
export default function enableCORS(
fn: (req: https.Request, res: e.Response) => Promise<void>
) {
return async (req: https.Request, res: e.Response) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', '*');
res.header(
'Access-Control-Allow-Methods',
'GET, POST, PUT, DELETE, OPTIONS'
);
res.header('Access-Control-Max-Age', '86400');
if (req.method === 'OPTIONS') {
res.end();
return;
}
await fn(req, res);
};
}
// src/index.ts
import enableCORS from './middlewares/enableCORS'
export const my_endpoint = https.onRequest(
enableCORS(async (request, response) => {
// Forward request
})
);
Despite setting up CORS headers, my browser requests are still being blocked. Can anyone offer assistance?