Expand description
§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);Structs§
- Redirect
- A representation of a redirect, with where it should go and its triggers.
- Redirect
Parse Error - Error struct for unparsable redirects. Includes line number and type of error.
- Redirects
- a
tower::Serviceto add redirects to a wrapped service. - Redirects
Layer - a
tower::Layerto add to atower::ServiceBuilderto add redirects.
Enums§
- Insert
Error - Represents errors that can occur when inserting a new route.
- Redirect
Parse Error Kind - Types of errors that can happen, e.g. wrong number of items on a row, unparsable status code.
- Response
Future - Future type which can return an unmodified request, a redirect, or an error if a value in the path capture is not a valid header value.