caddyserver / caddy

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

Inquiry on Using Starlark Scripting with Caddy #6325

Closed zong62296 closed 1 month ago

zong62296 commented 1 month ago

I recently came across the capability of using Starlark scripting with Caddy and am quite intrigued by the prospects it opens up for customizing and extending functionality. However, I've had a difficult time finding comprehensive documentation or examples on how to properly utilize Starlark scripts within the Caddy ecosystem.

Could you please provide guidance or point me to resources on the following:

  1. Getting Started with Starlark in Caddy: Any initial steps or prerequisites required to start using Starlark scripts with Caddy.

  2. Example Scripts: If possible, a few example Starlark scripts that demonstrate basic to intermediate usage within Caddy. This could include examples of modifying requests/responses, routing logic, or any other common use cases.

  3. Best Practices: Any best practices or recommendations when scripting with Starlark in the context of Caddy. This might include performance considerations, security practices, or common patterns.

  4. Troubleshooting and Debugging: Tips on how to troubleshoot and debug Starlark scripts when things don't go as expected.

I am quite excited about the potential to leverage Starlark to tailor my Caddy setup more closely to my needs but want to ensure I'm using it effectively and appropriately.

Thank you for any information or insights you can provide!

mholt commented 1 month ago

I recently came across the capability of using Starlark scripting with Caddy

This was discussed at one time, about 5 years ago, but as far as I know never came to fruition. Where did you find the capability?

zong62296 commented 1 month ago

@mholt On the Starlark official repo: https://github.com/bazelbuild/starlark/blob/master/users.md

zong62296 commented 1 month ago

It said that ---

Caddy is a fast, cross-platform HTTP/2 web server with automatic HTTPS. Starlark is used in Caddy 2 to extend the JSON configuration and add some logic.

francislavoie commented 1 month ago

Ah, no that's not true. We gave up on it because writing Caddy plugins in Go is so easy and doesn't require any additional work from us to provide (since Caddy was designed to be modular from the ground up). https://caddyserver.com/docs/extending-caddy

We are using https://github.com/google/cel-go though which is an embedded language, which allows for matching requests using a complex boolean expression. See https://caddyserver.com/docs/caddyfile/matchers#expression