Is it possible, from inside a lambda handler, to know the public hostname this function is accessed from?
For example, if I have a function on http://foo.netlify.com/.netlify/functions/debug, how can I know, from inside this function handler, that it’s running on
What I want to build:
My goal is to have one website available through multiple domain names. I added a redirect to my website so all incoming request to the root actually go through my lambda. Based on which domain is currently targeted, I want to return slightly different content.
What I tried
During development, I was using
netlify-lambda to locally serve my functions. In that context, I could read
event.headers.host and correctly get
localhost:9000 so I assumed this was the way to go.
But once I deployed in production, I realized the headers exposed are totally different and do not include any mention of the public hostname.
Other workaround I thought of
I thought that maybe I could redirect each domain to a different subdirectory and then add redirect rules for each of this subdirectories to pass and additional header mirroring the domain name.
www.foo1.com goes to
www.foo2.com goes to
foo.netlify.com/foo2 and then I add redirects such as
/foo1 goes to my lambda with
X-hostname: www.foo1.com as an additional header.
But I couldn’t find a way to have domains target anything else than the root, so I’m also blocked here.
Any idea, even an convoluted one, how I could have my lambdas aware of the url they’re running on?