Sample HTTP Middleware Plugin?

Is there a repo out there somewhere with a very basic http middleware plugin? I’ve been reading the docs here, but honestly, with just code snippets and not full files, it’s kind of hard to follow. Any examples or links that you could share would be very helpful!

I should probably put up a repo with a middleware stub that people can use as a template. I’ll try to do that this week sometime!

Whatcha building ? :grin:

I want to build a layout middleware (for lack of a better word) that takes the source files or proxied backend output and inserts it into a layout. I really don’t even understand if that’s possible but really want to play around with this and figure it out.

1 Like

@matt In my attempt to get my plugging working (I can’t get anything to work) I started reading the source code for the Markdown plugin. I guess I missed somehow when reading the documentation that you have templates included in the Markdown functionality!

Honestly, this probably solves my use case! The inclusion of front matter even solves the inevitable problem of needing to pass more than one block of text/code from the backend server to the template. So, I guess I don’t need to write a plugin after all … although, I’d really like to try my hand at it sometime.

1 Like

Except it doesn’t seem possible to use the markdown directive and the proxy directive together …

Either one or the other will handle the request; either it is proxied to a backend, or markdown renders the response.

I think there is a WIP implementation of using templates and proxy together, where templates can render a proxied page, but I don’t think it’s been extended to markdown.

@matt Interesting that you mention templates. I’ve been using http.templates with http.proxy for a project since last year and it works great!

What I actually want to do is avoid the need to include the template syntax in the proxied app. Right now, the app (ex. Rails) needs to return template syntax like so.

{{.Include "caddy-templates/rails/head/index.html"}} 
html from rails app ...

It would be very nice to have a layout/template that proxied content is render into, allowing you to make minimal changes to your backend app and just output the very minimal content that is needed to be plugged into your site template.

Looking at the Caddy markdown code gave me the idea of running the proxied content through something very similar, with templates and front matter. This would be very powerful!

This is the relevant part of my Caddyfile where I proxy requests to a Rails app that includes template syntax which is then rendered correctly by http.template. {
    root /somepath
    internal /caddy-templates
    templates / .html
    proxy /reporter/ http://localhost:3000 {

Looks like that WIP made it into the code with this commit.

For those who find this. It would seem that your plugin also needs to be listed in to work.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.