Is there an equivalent on Caddy2 for something like this:
<!--#include virtual="/cgi-bin/fortune.sh"-->
That is, the ability to include scripts within a web page served by Caddy2.
Is there an equivalent on Caddy2 for something like this:
<!--#include virtual="/cgi-bin/fortune.sh"-->
That is, the ability to include scripts within a web page served by Caddy2.
Yes, and itâs even better than server-side includes (SSI). See the templates
module:
See the include
and httpInclude
template actions.
This is used heavily on the Caddy website:
This doesnât look like it, quite. I might be wrong, but can I execute scripts with the templates
module? It is not simply inclusionâI used the wrong work on my original entryâbut execution and rendering near realtime. Do you have an example of a script execution using the templates
module?
Not by running an arbitrary shell script, no. The closest thing currently is httpInclude
which makes another HTTP request for more content.
Unfortunately we havenât bothered making the templates
module pluggable yet (to allow plugins to add their own functions) but that would be a possible refactor that would allow a plugin to provide this kind of functionality.
Iâm not sure arbitrary shell execution is something we necessarily want in the standard distribution of Caddy, itâs probably better left to a plugin to provide (once templates
is made extensible).
FYI, I opened up a feature request issue for this:
This topic was automatically closed after 30 days. New replies are no longer allowed.
FYI we just merged a change which makes templates
pluggable, so you can write your own plugin for Caddy to add functions to do whatever you need.