4 releases (2 breaking)
Uses new Rust 2024
| 0.3.0 | Nov 3, 2025 |
|---|---|
| 0.2.0 | Jun 5, 2025 |
| 0.1.1 | Nov 11, 2024 |
| 0.1.0 | Nov 11, 2024 |
#2315 in HTTP server
Used in tunnelbana
13KB
230 lines
tunnelbana-redirects
Generate redirect lists from cloudflare-style _redirects text files and serve them with tower.
Part of the tunnelbana project.
Example
use tower_http::services::ServeDir;
use tower::{ServiceBuilder, ServiceExt};
use http::Response;
use tunnelbana_redirects::RedirectsLayer;
let config = r#"
/example https://example.com 302
/subpath/{other}/final /{other}/final/ 302
/wildcard/{*wildcard} /{wildcard}
"#;
let redirects = tunnelbana_redirects::parse(config).expect("Failed to parse redirects");
let redirects_mw = RedirectsLayer::new(redirects).expect("Failed to route redirects");
let serve_dir = ServeDir::new("/var/www/html").append_index_html_on_directories(true);
let service = ServiceBuilder::new()
.layer(redirects_mw)
.service(serve_dir);
tunnelbana-redirects
Generate redirect lists from cloudflare-style _redirects text files and serve them with tower.
Dependencies
~6–8.5MB
~81K SLoC