How to conditionally apply a snipped base on the call method?

I defined a new site in my configuration via {
	reverse_proxy ntfy:80

It works :slight_smile:

I now would like to say

if the HTTP call is a POST or PUT then reverse proxy to ntfy:80 and if the method is GET then first apply the snippet authenticate-with-authelia

I always had time getting my head around such conditional structures in caddy and I did not find a matching example in the documentation

How can I do this?

It’s not possible to apply matchers to snippets. Snippets are simply fancy copy-paste.

Your snippet would have to have the matchers within, or you can import it into a handle which has a matcher.

Either way, what you’re trying to do seems like a mistake. POST and PUT should be authenticated, since they’re write operations. Authelia will remember auth by using a cookie.

That’s a good idea - thanks!

No, that’s fine. ntfy is a notifier and I want to leave it open. I just do not want to expose the web interface (for no particular reason), thus the limitation on the GET

But the web interface isn’t only GET, it’ll also include POST and PUT.

You should probably match request paths instead of methods.

I am not sure I understand.

I want to let PUT and POST requests access the endpoint freely.

I also want the web interface (that I GET from the endoint) to be limited (my Authelia configuration protects everything that comes from outside my home network). This is just to avoid unnecessary traffic on the web interface.

The web interface will also issue POST and PUT requests, which are available without restrictions.

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