diff options
| author | Fuwn <[email protected]> | 2022-06-02 00:40:54 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-06-02 00:40:54 +0000 |
| commit | bdc59defd1dada807ea0de08d190baecb4b44b35 (patch) | |
| tree | 589af4d3e01f6e771ee0fd0b8dacab6b5cc2701f | |
| parent | fix(gemini_to_html): replace redundancies (diff) | |
| download | september-bdc59defd1dada807ea0de08d190baecb4b44b35.tar.xz september-bdc59defd1dada807ea0de08d190baecb4b44b35.zip | |
feat(response): plain text routes
| -rw-r--r-- | .env.example | 1 | ||||
| -rw-r--r-- | README.md | 8 | ||||
| -rw-r--r-- | src/response.rs | 10 |
3 files changed, 18 insertions, 1 deletions
diff --git a/.env.example b/.env.example index cb69204..9331dcb 100644 --- a/.env.example +++ b/.env.example @@ -5,3 +5,4 @@ KEEP_GEMINI_EXACT=gemini://fuwn.me/skills # KEEP_GEMINI_DOMAIN=fuwn.me # PROXY_BY_DEFAULT=true FAVICON_EXTERNAL=https://host.fuwn.me/8te8lw0lxm03.webp +PLAIN_TEXT_ROUTE=/robots.txt @@ -125,6 +125,14 @@ An external favicon file to apply to the HTML response. FAVICON_EXTERNAL=https://host.fuwn.me/8te8lw0lxm03.webp ``` +### `PLAIN_TEXT_ROUTE` + +A comma-seperated list of paths to treat as plain text routes. + +```dotenv +PLAIN_TEXT_ROUTE=/robots.txt,/license.txt +``` + ## Styling Want to give your website a shiny new look? Try using one of sources diff --git a/src/response.rs b/src/response.rs index 46acfa6..d69efb2 100644 --- a/src/response.rs +++ b/src/response.rs @@ -120,7 +120,15 @@ pub async fn default( env!("VERGEN_GIT_SHA").get(0..5).unwrap_or("UNKNOWN"), )); - // Return HTML response + if let Ok(plain_texts) = var("PLAIN_TEXT_ROUTE") { + if plain_texts.split(',').any(|r| r == req.path()) { + return Ok( + HttpResponse::Ok() + .body(String::from_utf8_lossy(&response.data).to_string()), + ); + } + } + Ok( HttpResponse::Ok() .content_type("text/html; charset=utf-8") |