Created
June 28, 2022 18:14
-
-
Save FazioNico/15d797a46e9196f5f043ae54a8f40c6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as functions from "firebase-functions"; | |
import { Request, Response } from "firebase-functions"; | |
import * as cors from 'cors'; | |
const corsHandler = cors({origin: true}); | |
// Start writing Firebase Functions | |
// https://firebase.google.com/docs/functions/typescript | |
export const helloWorld = functions.https.onRequest((request: Request, response: Response) => { | |
corsHandler(request, response, () => { | |
functions.logger.info("Hello logs!", {structuredData: true}); | |
// browsers like chrome need these headers to be present in response if the api is called from other than its base domain | |
response.set("Access-Control-Allow-Origin", "*"); // you can also whitelist a specific domain like "http://127.0.0.1:4000" | |
response.set("Access-Control-Allow-Headers", "Content-Type"); | |
response.json({"message": "Hello from Firebase!"}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment