-
Notifications
You must be signed in to change notification settings - Fork 233
fix: avoid CORS declaration interop requirement #1941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { onCall } from "firebase-functions/v2/https"; | ||
|
|
||
| onCall({ cors: true }, () => null); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "module": "commonjs", | ||
| "moduleResolution": "node", | ||
| "noEmit": true, | ||
| "strict": true, | ||
| "target": "es2022" | ||
| }, | ||
| "files": ["index.ts"] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| // SOFTWARE. | ||
|
|
||
| import cors from "cors"; | ||
| import * as cors from "cors"; | ||
| import * as express from "express"; | ||
| import { DecodedAppCheckToken } from "firebase-admin/app-check"; | ||
|
|
||
|
|
@@ -796,7 +796,7 @@ export function onCallHandler<Req = any, Res = any, Stream = unknown>( | |
| ...options.cors, | ||
| origin, | ||
| }; | ||
| cors(corsOptions as cors.CorsOptions)(req, res, () => { | ||
| cors.default(corsOptions)(req, res, () => { | ||
| resolve(wrapped(req, res)); | ||
| }); | ||
|
Comment on lines
+799
to
801
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Directly calling However, in some environments (such as running tests directly on source files, or using certain toolchains/bundlers where Using a fallback like const corsFn = (cors.default || cors) as any;
corsFn(corsOptions)(req, res, () => {
resolve(wrapped(req, res));
}); |
||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using the
process.argv[1]trick to pass the path to the inline Node script, you can directly interpolate the$SCRIPT_DIRvariable into the double-quoted Node script string. This is much cleaner, more readable, and standard for bash scripts.