Skip to content

WIP: add http middleware template#3617

Draft
michelleN wants to merge 1 commit into
spinframework:mainfrom
michelleN:middleware-template
Draft

WIP: add http middleware template#3617
michelleN wants to merge 1 commit into
spinframework:mainfrom
michelleN:middleware-template

Conversation

@michelleN

@michelleN michelleN commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Opened up this draft PR as an additional resource to visualize #3618.
This is an attempt to add an http middleware template for both the spin new and spin add experience. I ran into a few issues.

Signed-off-by: Michelle Dhanani <mdhanani@akamai.com>
@@ -0,0 +1,10 @@
[[trigger.http]]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current templating system requires the add snippet to contain a trigger section which doesn't make sense for a middleware component (or any library component).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, weird. I think we used to check the trigger to make sure it was the same as existing triggers. I don't think that would be needed any more - let's see how the trigger info is being depended on and see if we can bin it off.

[add_component]
skip_files = ["spin.toml"]
[add_component.snippets]
component = "component.txt"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding middleware to an existing app would require post add instructions including adding the middleware to dependencies under the correct trigger section.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be unavoidable - presumably the reason you're building your thing as middleware rather than including it in component source code is that you want to apply it to multiple triggers. (Although I guess another case is "my app is an off-the-shelf component like the fileserver but I want to wrap it." So maybe sometimes we do want to be able to auto-add it to triggers. But yeah, we don't have syntax for that yet.)

@@ -0,0 +1,14 @@
spin_manifest_version = 2

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's not really a clear way to test middleware as a standalone spin app unless we revive (I think)spin test

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I briefly looked at a middleware template, I assumed it would have to be add-only (not available in spin new). Even with spin test it's not clear how a standalone piece of middleware could work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants