aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--README.md6
-rw-r--r--src/main.rs3
-rw-r--r--src/post.rs6
5 files changed, 13 insertions, 6 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4eb3689..182aec3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -215,7 +215,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chela"
-version = "1.3.0"
+version = "1.4.0"
dependencies = [
"axum",
"chrono",
diff --git a/Cargo.toml b/Cargo.toml
index fa40a86..a4e891a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "chela"
-version = "1.3.0"
+version = "1.4.0"
edition = "2021"
license = "BSL-1.0"
diff --git a/README.md b/README.md
index 9ebf79d..861f206 100644
--- a/README.md
+++ b/README.md
@@ -71,6 +71,9 @@ If you would like Chela to listen for HTTP requests over a Unix socket, set this
##### `CHELA_ALPHABET`
If this variable is set, Chela will use the characters in `CHELA_ALPHABET` to create IDs for URLs. The default alphabet is `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`. See [here](https://sqids.org/faq#unique) for more information on Sqids alphabets.
+##### `CHELA_USES_HTTPS`
+If this variable is set, Chela will refer to itself as `https://$CHELA_HOST` instead of the default `http://$CHELA_HOST`.
+
### Manually
#### Build
```bash
@@ -94,7 +97,7 @@ If you would prefer to be the only one able to access these pages, then you can
```nginx
server {
- server_name example.com;
+ server_name a.com;
location / {
proxy_pass http://localhost:3000;
@@ -108,7 +111,6 @@ server {
location /tracking {
proxy_pass http://localhost:3000$request_uri;
- proxy_set_header X-Real-IP $remote_addr;
auth_basic 'Restricted';
auth_basic_user_file /path/to/your/.htpasswd;
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(),