SebastianG
SebastianG

Reputation: 9612

Getting full url in express app running as firebase function -- including the function name?

This seems a bit more challenging than just generally getting the url + path due to express being served from a secondary path.

I'm trying to dynamically create redirect/callback URL's for passport based OpenID integrations.

So far, I've successfully gotten as much using the req.host as directed in other stackoverflow threads:

callbackURL: "https://" + req.get("host") + "/auth/apple/redirect",

I do not need protocol as I'm only dealing with https all the time.

The issue is, my function is being served from:

https://europe-west2-projectname.cloudfunctions.net/MY_FUNCTION_NAME/

and therefore using just host, the url above will not be a valid redirect URL that Oauth can use.

I am doing this as I have 1 single app running off of 2 different functions depending if i'm in staging OR production.

To further add insult to injury -- firebase functions within the same app seem to share their environmental variables so I can't really count on those either.

Upvotes: 3

Views: 518

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317968

According to the Google Cloud documentation:

  • node 6 and 8 offer FUNCTION_NAME as an environment variable that indicates which function is being run.
  • node 10 offers FUNCTION_TARGET.

Upvotes: 2

Related Questions