aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-06-02 00:40:54 +0000
committerFuwn <[email protected]>2022-06-02 00:40:54 +0000
commitbdc59defd1dada807ea0de08d190baecb4b44b35 (patch)
tree589af4d3e01f6e771ee0fd0b8dacab6b5cc2701f
parentfix(gemini_to_html): replace redundancies (diff)
downloadseptember-bdc59defd1dada807ea0de08d190baecb4b44b35.tar.xz
september-bdc59defd1dada807ea0de08d190baecb4b44b35.zip
feat(response): plain text routes
-rw-r--r--.env.example1
-rw-r--r--README.md8
-rw-r--r--src/response.rs10
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
diff --git a/README.md b/README.md
index d071850..fbec19a 100644
--- a/README.md
+++ b/README.md
@@ -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")