Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/edudobay/caddy-varsdirective
Allow setting custom variables from a Caddyfile
https://github.com/edudobay/caddy-varsdirective
Last synced: about 2 months ago
JSON representation
Allow setting custom variables from a Caddyfile
- Host: GitHub
- URL: https://github.com/edudobay/caddy-varsdirective
- Owner: edudobay
- Created: 2022-01-02T22:31:38.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-02T22:34:12.000Z (about 3 years ago)
- Last Synced: 2024-06-20T16:32:23.871Z (7 months ago)
- Language: Go
- Size: 54.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Caddy vars directive
[Caddy][] provides the [http.handlers.vars][] module, but it isn't available for use in a `Caddyfile`. Sometimes setting a variable might be useful but not worth abandoning the simplicity of the Caddyfile configuration format.
## Setup
Build with [xcaddy][]:
```
xcaddy build --with github.com/edudobay/caddy-varsdirective
```## Motivation and example usage
Rewriting the URL in a PHP/FastCGI app is not so obvious (see [this thread](https://caddy.community/t/symfony-with-uri-prefix/10148/3) for an explanation). In this example, we remove the `/_api` prefix, if present, and also remove trailing slashes.
```
route {
uri strip_prefix /_api
uri strip_suffix /
set_var resolved_uri {path}
php_fastcgi localhost:9000 {
env REQUEST_URI {http.vars.resolved_uri}
}
}
```[Caddy]: https://caddyserver.com/
[http.handlers.vars]: https://caddyserver.com/docs/modules/http.handlers.vars
[xcaddy]: https://github.com/caddyserver/xcaddy