diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 3 | ||||
-rw-r--r-- | src/post.rs | 6 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 83731fa..b3e8abb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,7 @@ pub struct ServerState { pub sqids: Sqids, pub main_page_redirect: Option<Url>, pub behind_proxy: bool, + pub uses_https: bool, } #[derive(Debug, Clone, sqlx::FromRow, PartialEq, Eq)] @@ -87,12 +88,14 @@ async fn main() -> eyre::Result<()> { .build()?; let main_page_redirect = env::var("CHELA_MAIN_PAGE_REDIRECT").unwrap_or_default(); let behind_proxy = env::var("CHELA_BEHIND_PROXY").is_ok(); + let uses_https = env::var("CHELA_USES_HTTPS").is_ok(); let server_state = ServerState { db_pool, host, sqids, main_page_redirect: Url::parse(&main_page_redirect).ok(), behind_proxy, + uses_https }; serve(server_state).await?; diff --git a/src/post.rs b/src/post.rs index e19d6ae..bac5c06 100644 --- a/src/post.rs +++ b/src/post.rs @@ -32,7 +32,8 @@ pub async fn create_link( if id.exists { log!("Serving cached id {} -> {}", id.id, form.url.as_str()); return Html(format!( - r#"<pre>http://{}/{} -> <a href="{}"">{}</a></pre>"#, + r#"<pre>http{}://{}/{} -> <a href="{}"">{}</a></pre>"#, + if state.uses_https { "s" } else { "" }, state.host, id.id, form.url.as_str(), @@ -72,7 +73,8 @@ VALUES ($1,$2,true) return ( StatusCode::OK, Html(format!( - r#"<pre>http://{}/{} -> <a href="{}"">{}</a></pre>"#, + r#"<pre>http{}://{}/{} -> <a href="{}"">{}</a></pre>"#, + if state.uses_https { "s" } else { "" }, state.host, id.id, form.url.as_str(), |