caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
55.72k stars 3.92k forks source link

[Idea/Question] How to integrate caddy server with the go script language tengo? #4255

Closed diyism closed 2 years ago

diyism commented 2 years ago

I know that the algernon web server can run gopher-lua script (https://github.com/xyproto/algernon)

How to let caddy server to run tengo script to serve a web site? (https://github.com/d5/tengo)

Or Is there any other golang script supported by caddy server?

francislavoie commented 2 years ago

You can write a custom module which would let you do this: https://caddyserver.com/docs/extending-caddy

But you'd probably be better off just what your script in Go instead of delegating it to a script.

We had plans early on in the development of Caddy v2 to use Starlark for scripting, but with how easy modules are to write, it hasn't been a priority to implement scripting support.

Related issue https://github.com/caddyserver/caddy/issues/2690

mholt commented 2 years ago

Yeah, we still like the idea of a Starlark module, but decided it doesn't have to be baked in -- and it's a lot of work -- so we deprioritized it; but that doesn't mean you can't write your own module for something like dynamic scripts!

diyism commented 7 months ago

Nowadays, I'm still dreaming of a caddy module that supports tengo script, in my dream: the best golang web server(caddy) + the best golang script language(tengo) + the best web page template(svelte, currently the golang version(plenti) is not as fast as the bun/node version(svelte-bun) https://github.com/xyproto/algernon/issues/125 )

francislavoie commented 7 months ago

Why not just write a Caddy plugin for what you need? It's trivial, and building is very easy with xcaddy.

Or, just write the Tengo plugin yourself, it shouldn't be too hard.

We have no plans to work on this because we don't have a need for it, the cost-benefit ratio is not good enough for us to spend time on this when we could focus on other things.

mholt commented 7 months ago

I don't think it's a priority for us right now for the reasons Francis mentioned, but I could work on it with a suitable sponsorship. Or, of course anyone else is welcome to implement it themselves in the meantime. 👍

diyism commented 7 months ago

Thanks, I'll give a try to build a tengo caddy plugin.

mholt commented 7 months ago

Cool! Please share it with us and the community once you have it :grinning: