I have a FE application (CRA) with some functions.
I’d like to know how the FE app can programmatically get the location of the deployed functions?
I have a FE application (CRA) with some functions.
I’d like to know how the FE app can programmatically get the location of the deployed functions?
Hi @scarter1,
I’m not completely sure what you’re asking. Any deployed function is located at /.netlify/functions/<function-name>/
path (relative to the root of the website). Is that what you’re after?
I mean how do I know in the FE what url/domain I should use to hit the endpoint?
Is it available via an environment variable?
I already answered that. The path is: /.netlify/functions/<function-name>/
.
And what about the domain?
That is your Netlify sub-domain or any custom domain attached to the website.
Ok, Missed the rest of your comment about it being relative to the website root
So how do I get the subdomain that netlify uses for a specific deployment?
I’ve pushed 2 different branches with the same commit history, and both end up on different url with different build numbers?
Like wise for PRs and main branches?
OK, looks like I can use the DEPLOY_URL
env var.
If you use relative URLs in your application, you should not have this problem. They will always be at /.netlify/functions/<function-name>/
of that particular deploy.
If you need to use absolute URLs, you can use DEPLOY_URL
variable, but I don’t see the point of this. You’d need absolute URLs only when you need to host functions on a different website and front end on a different one, or if you wish to use functions from other deploy. In both these cases, the environment variable is useless. Plus, you’d have CORS issues. So, it’s better to stick to relative URLs.