Sharing/distributing custom edge handlers
shortdiv opened this issue · 12 comments
Which problem is this feature request solving?
Once edge handlers are released, partners will likely want to write custom edge handlers and share them for use i.e. Contentful edge handlers that ping the api to grab new content
Is the idea that partners will create custom edge handlers as build plugins? I see a potential issue with this already since our edge handlers deploy plugin is a core plugin that runs last 🤔
Describe the solution you'd like
Figure out a workflow to enable partners to share code and for users to easily consume them in projects
Describe alternatives you've considered
???
A potential idea would be to have the build plugin have access to published handlers similar to how buildbot picks up all published build plugins and enable a user to pass in a specific handler via config in inputs. 💭
I see a potential issue with this already since our edge handlers deploy plugin is a core plugin that runs last
isn't that a good thing? so other plugins can dump in their handlers before we bundle? at least that was kinda the reason we wanted to have core running last
why not have partners release them as npm packages, so people would use them like this?
export { onRequest } from "the-partner-handler-package";Yeah good point, if we had build plugins build into an edge handlers directory it would work. Since the handler directory is customizable, we'd have to make sure partner plugins have an input to change where the output builds to
Since the handler directory is customizable, we'd have to make sure partner plugins have an input to change where the output builds to
it's not customizable right now. as soon as it is, build plugins can read it from the config object they get passed
Another idea could be to do what we are doing with Netlify Functions. Partners might also want to provide specific Netlify Functions.
To do this, they can write a Build plugin that create or update the Site's Functions. We also provide with an utility for plugins that want to list the Site's Functions files (we have two plugins doing so).
Similarly, a partner wanting to distribute Edge handlers could write a Build plugin that would create that file inside edge-handlers/ during onPreBuild or onBuild. We could provide with a plugin utils to simplify that logic. We might not even need to since this is as simple as creating a file. The only thing we might need is to expose the edge handlers source and destination directories as constants (like we do for Functions).
It would be great if users could install Edge handlers from the UI like they do with Build plugins. It would also be great if developers could share Edge handlers in a simple way, without having to use utilities, etc.
What about this: if you want to share/distribute Edge handlers, create a Build plugins with an edge-handlers directory. That'd be simple and straightforward. The Edge handlers would be copied to .netlify/edge-handlers on each build, right before bundling.
What do you think?
The Edge handlers would be copied to
.netlify/edge-handlerson each build, right before bundling.
Technically, the edge handler would have to be uploaded to the configured edge handler directory to be picked up by our bundler.
Can we drop this issue for now? it's not relevant for the launch at all and we need to focus on other things.
Technically, the edge handler would have to be uploaded to the configured edge handler directory to be picked up by our bundler.
Just to be clear, this directory would be copied before bundling, so it should be picked up.
i don't understand. can you somehow explain the workflow in bullet point steps and clearly indicate what component would do what action?
I think this might be more of a product question (do we want users to share Edge handlers?) more than technical, but https://github.com/netlify/pod-the-builder/issues/63 is outlining that specific angle. From that perspective, I'd be ok closing this issue if @shortdiv is.
To come back to the specific implementation suggested above (but several other implementation could equally work):
- Community build plugin contains
edge-handlersdirectory - Before Edge handlers plugin runs, that directory is merged with the Site's
edge-handlersdirectory. As an alternative, the merging could also happen in-memory, instead of the filesystem. - Edge handlers plugin reads the content of the merged Edge handlers directory, creates bundles in
.netlify/edge-handlersand uploads them.
I'm ok with closing this issue for now ^