Database connection

Hi,
I may just be just a little disoriented but:
Is there a caddy plugin to connect to a (any) database?
I‘d like to be able to block requests based on an external source of data, like Redis (or sqlite or some sql database).
This is a use case so obvious that something must exist, already, still I didn‘t find anything and I‘m close to writing something.

Thanks for the question. I’m not sure I understand though: connect to the DB and then do what?

Forgive me but this is not obvious, I am not sure why you’d need to connect to a database (either I can’t think of a reason, or I can think of infinitely too many reasons such that there will be no plugin that does all of them…)

I‘m sorry, my question was incomplete and badly written.
The extension geoip2 does lookup a requests ip in a local geoip database so that the result can be used later on to eg. filter requests.
I‘d like to query a ‘regular’ database using parts of a request (not necessarily only the ip) and then use the result further on in the response.

caddy-geoip2

Edit to add: The implementation of geoip seems to be very straight forward, I may just try to use it as a starting point for an own implementation.

1 Like

I see; so you basically want to run a configurable DB query to help handle requests?

You’ll need to write your own plugin for that. Nothing of the sort exists.

Yes, that’s what I’m looking for. I have no idea whether this is a good idea concerning performance, but since geoip2 exists I guess it is possible at least using sqlite or redis.

Thanks, I’ll try, watch this space :slight_smile:

There is kind of a plugin that supports database queries, it’s an extended template library called xtemplate:

I don’t know if that may be of help to you, but worth a look.

1 Like

Thank you, while not really matching my use case it still has some interesting hints.

1 Like

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