Access function complete url from the function itlself

Hi

I was wondering if it possible to access the complete URL of a function from the function itself?
The event object contains the path and query parameters, but not the hostname/domain piece
https://docs.netlify.com/functions/build-with-javascript/#format

For example, one of my functions would like to determine if it is running under myuser.netlify.com or branch--myuser.netlify.com.

Alternatively, there is maybe a way to reference “relative” resources within the function code?
Example:
myuser.netlify.com/.netlify/functions/hello generates a link to myuser.netlify.com/img/hello.png
and
branch--myuser.netlify.com/.netlify/functions/hello generates a link to branch--myuser.netlify.com/img/hello.png

Thanks!

Hi @tvanier, it’s possible to get the site url from the context object, specifically context.clientContext.custom.netlify. The following snippet shows how you would decode the base64-encoded data using javascript:

function extractNetlifySiteFromContext(context) {
  data = context.clientContext.custom.netlify
  decoded = JSON.parse(Buffer.from(data, "base64").toString("utf-8"))
  return decoded

Let me know if that works for you.