Netlify Dev vs Live function URLs

Netlify site name: (doesn’t do a lot)

I’m a little confused about calling calling functions locally vs on live.

Does Netlify Dev automatically intercept requests to my live functions and redirect the request to the locally hosted function?

Or do I need to write that logic into my app to make sure that I’m calling the function in the correct place?

If it’s the latter, what’s the best practise for detecting whether I’m running my app inside Netlify Dev vs on live?


If you write a function that targets /.netlify/functions/<YOUR_FUNCTION_NAME>, that will resolve to the function for the that environment whether it be prod, deploy-preview, or local via netlify dev. Yes, dev will intercept your requests and route them to a locally-running Functions server that it spins up for you :slight_smile:


1 Like


So basically, whether I’m writing client side code that calls a function or a function that calls a function, I can just use /.netlify/functions/<YOUR_FUNCTION_NAME> and it’ll just work?


:thinking: that one may not be so easy; Functions themselves aren’t aware that they’re attached to a website per se. I wouldn’t expect something like


to work inside a Function, fetching another function. I think to accomplish that you may need to stitch together some data from the event object:

exports.handler = (event, context) => {
  const runningAt = + event.path

  return {
    statusCode: 200,
    body: `I'm running at ${runningAt}`

Which comes out looking like


That’s how I’d recommend resolving current host/location it for function-to-function calls; but yes for front-end-to-function calls, they will automatically be environment-specific


Okay I can work with that.

Thank you so much for the explanation!