firebase-backend
firebase-backend copied to clipboard
Add Cors options for Restful Endpoints
The package uses the express router. We should probably be able to enable CORS like in Google's example: https://firebase.google.com/docs/functions/http-events#using_existing_express_apps
Or somehow be able to define CORS configuration for each function / route: https://github.com/expressjs/cors#enable-cors-for-a-single-route
This can be implemented either or in both ways but it is something that will be required. I don't know the security concerns with setting cors enabled to true for all functions so:
- We should default to cors enabled false
- Add an option to the function parser to set the default true for all Restful functions.
This will make it so that the devs that want it on for everything can do that, the ones that don't won't have to change anything.
PR has been made. It's been stuck on review for a while. Have requested a readme update as well and it'll be merged in.
Looks great!
Any update on this?
I'm having some problems with CORS, im using Firebase Hosting and the functions show this error when I try to call them:
my cors config is this:
any idea?
I am still getting cors errors (using v0.2.4). Can someone verify that the new enableCors
setting actually works?
Ah sorry my fault, I typed the wrong URL in my request. I can say it works :)
@ejuvaleru Since you "liked" my post, make sure you are running version 0.2.4 and put {enableCors: true}
either on your FunctionParser
(index.ts) or on your endpoint.
Examples:
exports = new FunctionParser(__dirname, exports, { enableCors: true }).exports;
export default new Post(async (request: Request, response: Response) => { ... }, { enableCors: true })