feat(functions): implement serve individual functions #4703
+102
−28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
the
supabase functions servecommand is ignoring function name arguments and always serves all functions.I think the expected behaviour is for it to accept function names as arguments (similar to
deploy). I’ve collected a few places where the examplesupabase functions serve hello-worldis used throughout the docs:https://supabase.com/docs/guides/functions/development-tips#skipping-authorization-checks
https://supabase.com/docs/guides/functions/function-configuration#skipping-authorization-checks
https://supabase.com/docs/guides/functions/quickstart-dashboard#cli
https://supabase.com/docs/guides/functions/quickstart#step-3-test-your-function-locally
https://supabase.com/docs/guides/functions/secrets#local-secrets
with the changes in this PR, it would be now possible to do:
supabase functions serve hello-worldsupabase functions serve fun1 fun2 fun3etc…It also, addresses this issue: #4395
and adds tests.
It might look some tests are redundant, but I thought it would be better to cover these different cases, because we are going from ignored to any amount of functions. and, about this
—allhidden flag implementation, I added a comment about that, because it currently has no effect.I also added slug validation to the
servecommand for the case where the function is not mentioned in the 'config.toml' file, this might allow to catch invalid slugs earlier in the development.did many tests by hand, testing different combinations of functions and calling all function endpoints to check which of them are listening, like:
running:

checking:

I did not touch the file watcher, it keeps watching all functions, regardless of which ones are being served. I can implement that in a subsequent PR if you guys find it relevant. Although I think it might not be too relevant.
Lastly, there is kind of a bug (not introduced by this PR), where we are allowing "non existent functions" to be served (which naturally results in
BOOT_ERRORof the deno worker as it doesn't find the file when it comes the time to get it, when the function is called). I was fixing that putting a check inside the "PopulatePerFunctionConfigs" function, but then the refactor of tests (mocking the existence of function files) was ocupying the most part of changes, so I reverted. I would like to know what are your thoughts on that, if that is relevant of course.