'Forwarding' or `next()`-ing Netlify Functions?

I was looking at the documentation of the new Netlify Edge Functions, where there is a concept of calling await next() in a handler: Edge Functions API | Netlify Docs. This allows the following really nice pattern:

export default (req, ctx) => {
  const auth = checkAuth();

  // Forbidden
  if(!auth) return new Response(null, {status: 403});

  // User is authenticated, continue request as normal
  return await ctx.next();

Which allows you to sort of ‘protect’ assets. For example, I might have some images that I would only want authenticated users to be able to see, I could put a route handler like this in between, using Edge Functions.

The problem is; I already have an existing app, and it uses some Nodejs libraries that are not supported in Deno. So I won’t be able to migrate my app to Edge Functions any time soon. I cannot, however, find a similar kind of next functionality in the ‘regular’ Netlify Functions. Could anyone point out to me if the pattern I described would be possible using ‘regular’ Netlify Functions? Could I potentially make a feature request, even?

You have already made the feature request merely by asking :slight_smile: I’ve forwarded this to our product team.

I don’t know of any way to do that today, with our regular functions, since they aren’t “aware” of each other in the way that our edge functions are - were you to “pass through” one, there is no “obvious/planned” next one that is lined up to run, unlike edge functions which are ordered and all intended to run with every request (with a matching path). You could certainly have a function call another function directly, (if conditions are met, such as authenticated users only), but then the runtime for both would be limited by the timeout on the first function. As you seem to be a Pro customer, we can up the timeout for you to 26s, but that might not be a great customer experience (for your visitors). Nonetheless, let me know if you’d like that; it’s easy for us to do and could give you room to run the workflow of your dreams :wink:

1 Like