♻️ Simple & Efficient Gemini-to-HTTP Proxy fuwn.net
proxy gemini-protocol protocol gemini http rust
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: remove semi-outdated technical information

Fuwn 28fbcfde a27dd14f

+2 -24
+2 -12
src/main.rs
··· 14 14 mod response; 15 15 mod url; 16 16 17 - #[macro_use] extern crate log; 17 + #[macro_use] 18 + extern crate log; 18 19 19 20 use {actix_web::web, response::default, std::env::var}; 20 21 21 22 #[actix_web::main] 22 23 async fn main() -> std::io::Result<()> { 23 - // Set the `RUST_LOG` environment variable so Actix can provide logs. 24 - // 25 - // This can be overridden using the `RUST_LOG` environment variable in 26 - // configuration. 27 24 std::env::set_var("RUST_LOG", "actix_web=info"); 28 - 29 - // Initialise `dotenv` so we can access `.env` files. 30 25 dotenv::dotenv().ok(); 31 - // Initialise logger so we can see logs 32 26 pretty_env_logger::init(); 33 27 34 - // Setup Actix web-server 35 28 actix_web::HttpServer::new(move || { 36 29 actix_web::App::new() 37 30 .default_service(web::get().to(default)) 38 31 .wrap(actix_web::middleware::Logger::default()) 39 32 }) 40 33 .bind(( 41 - // Bind Actix web-server to localhost 42 34 "0.0.0.0", 43 - // If the `PORT` environment variable is present, try to use it, otherwise; 44 - // use port `80`. 45 35 var("PORT").map_or(80, |port| match port.parse::<_>() { 46 36 Ok(port) => port, 47 37 Err(e) => {
-10
src/response.rs
··· 25 25 let mut is_proxy = false; 26 26 let mut is_raw = false; 27 27 let mut is_nocss = false; 28 - // Try to construct a Gemini URL 29 28 let url = match url_from_path( 30 29 &format!("{}{}", req.path(), { 31 30 if !req.query_string().is_empty() || req.uri().to_string().ends_with('?') ··· 49 48 ); 50 49 } 51 50 }; 52 - // Make a request to get Gemini content and time it. 53 51 let mut timer = Instant::now(); 54 52 let mut response = match germ::request::request(&url).await { 55 53 Ok(response) => response, ··· 94 92 let language = 95 93 meta.parameters().get("lang").map_or_else(String::new, ToString::to_string); 96 94 97 - // Reset timer for below 98 95 timer = Instant::now(); 99 96 100 - // Convert Gemini Response to HTML and time it. 101 97 let mut html_context = if is_raw { 102 98 String::new() 103 99 } else { ··· 137 133 ); 138 134 } 139 135 140 - // Try to add an external stylesheet from the `CSS_EXTERNAL` environment 141 - // variable. 142 136 if let Ok(css) = var("CSS_EXTERNAL") { 143 137 let stylesheets = 144 138 css.split(',').filter(|s| !s.is_empty()).collect::<Vec<_>>(); ··· 160 154 } 161 155 } 162 156 163 - // Try to add an external favicon from the `FAVICON_EXTERNAL` environment 164 - // variable. 165 157 if let Ok(favicon) = var("FAVICON_EXTERNAL") { 166 158 html_context.push_str(&format!( 167 159 "<link rel=\"icon\" type=\"image/x-icon\" href=\"{favicon}\">", ··· 182 174 html_context.push_str(&head); 183 175 } 184 176 185 - // Add a title to HTML response 186 177 html_context.push_str(&format!("<title>{gemini_title}</title>")); 187 178 html_context.push_str("</head><body>"); 188 179 ··· 216 207 _ => html_context.push_str(&format!("<p>{}</p>", response.meta())), 217 208 } 218 209 219 - // Add proxy information to footer of HTML response 220 210 html_context.push_str(&format!( 221 211 "<details>\n<summary>Proxy Information</summary> 222 212 <dl>
-2
src/url.rs
··· 44 44 if fallback { "/" } else { "" } 45 45 ) 46 46 } else { 47 - // Try to set `ROOT` as `ROOT` environment variable, or use 48 - // `"gemini://fuwn.me"` as default. 49 47 format!( 50 48 "{}{}{}", 51 49 {