···1414mod response;
1515mod url;
16161717-#[macro_use] extern crate log;
1717+#[macro_use]
1818+extern crate log;
18191920use {actix_web::web, response::default, std::env::var};
20212122#[actix_web::main]
2223async fn main() -> std::io::Result<()> {
2323- // Set the `RUST_LOG` environment variable so Actix can provide logs.
2424- //
2525- // This can be overridden using the `RUST_LOG` environment variable in
2626- // configuration.
2724 std::env::set_var("RUST_LOG", "actix_web=info");
2828-2929- // Initialise `dotenv` so we can access `.env` files.
3025 dotenv::dotenv().ok();
3131- // Initialise logger so we can see logs
3226 pretty_env_logger::init();
33273434- // Setup Actix web-server
3528 actix_web::HttpServer::new(move || {
3629 actix_web::App::new()
3730 .default_service(web::get().to(default))
3831 .wrap(actix_web::middleware::Logger::default())
3932 })
4033 .bind((
4141- // Bind Actix web-server to localhost
4234 "0.0.0.0",
4343- // If the `PORT` environment variable is present, try to use it, otherwise;
4444- // use port `80`.
4535 var("PORT").map_or(80, |port| match port.parse::<_>() {
4636 Ok(port) => port,
4737 Err(e) => {
-10
src/response.rs
···2525 let mut is_proxy = false;
2626 let mut is_raw = false;
2727 let mut is_nocss = false;
2828- // Try to construct a Gemini URL
2928 let url = match url_from_path(
3029 &format!("{}{}", req.path(), {
3130 if !req.query_string().is_empty() || req.uri().to_string().ends_with('?')
···4948 );
5049 }
5150 };
5252- // Make a request to get Gemini content and time it.
5351 let mut timer = Instant::now();
5452 let mut response = match germ::request::request(&url).await {
5553 Ok(response) => response,
···9492 let language =
9593 meta.parameters().get("lang").map_or_else(String::new, ToString::to_string);
96949797- // Reset timer for below
9895 timer = Instant::now();
9996100100- // Convert Gemini Response to HTML and time it.
10197 let mut html_context = if is_raw {
10298 String::new()
10399 } else {
···137133 );
138134 }
139135140140- // Try to add an external stylesheet from the `CSS_EXTERNAL` environment
141141- // variable.
142136 if let Ok(css) = var("CSS_EXTERNAL") {
143137 let stylesheets =
144138 css.split(',').filter(|s| !s.is_empty()).collect::<Vec<_>>();
···160154 }
161155 }
162156163163- // Try to add an external favicon from the `FAVICON_EXTERNAL` environment
164164- // variable.
165157 if let Ok(favicon) = var("FAVICON_EXTERNAL") {
166158 html_context.push_str(&format!(
167159 "<link rel=\"icon\" type=\"image/x-icon\" href=\"{favicon}\">",
···182174 html_context.push_str(&head);
183175 }
184176185185- // Add a title to HTML response
186177 html_context.push_str(&format!("<title>{gemini_title}</title>"));
187178 html_context.push_str("</head><body>");
188179···216207 _ => html_context.push_str(&format!("<p>{}</p>", response.meta())),
217208 }
218209219219- // Add proxy information to footer of HTML response
220210 html_context.push_str(&format!(
221211 "<details>\n<summary>Proxy Information</summary>
222212<dl>
-2
src/url.rs
···4444 if fallback { "/" } else { "" }
4545 )
4646 } else {
4747- // Try to set `ROOT` as `ROOT` environment variable, or use
4848- // `"gemini://fuwn.me"` as default.
4947 format!(
5048 "{}{}{}",
5149 {