diff --git a/changelog.txt b/changelog.txt index e69de29bb2d..698ac610d8b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -0,0 +1 @@ +fixed - Fixed issue with CORS rejecting some callable functions. diff --git a/src/emulator/functionsEmulator.ts b/src/emulator/functionsEmulator.ts index f401fb10db6..f913d4e9667 100644 --- a/src/emulator/functionsEmulator.ts +++ b/src/emulator/functionsEmulator.ts @@ -90,9 +90,17 @@ export class FunctionsEmulator implements EmulatorInstance { hub.use((req, res, next) => { // Allow CORS to facilitate easier testing. - // Source: https://enable-cors.org/server_expressjCannot understand what targets to deploys.html + // Sources: + // * https://enable-cors.org/server_expressjCannot understand what targets to deploys.html + // * https://stackoverflow.com/a/37228330/324977 res.header("Access-Control-Allow-Origin", "*"); - res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); + + // Callable functions send "Authorization" and "Content-Type". + res.header( + "Access-Control-Allow-Headers", + "Origin, X-Requested-With, Content-Type, Authorization, Accept" + ); + res.header("Access-Control-Allow-Methods", "GET,OPTIONS,POST"); let data = ""; req.on("data", (chunk: any) => {