Add CHELA_USES_HTTPS as an option
Some checks failed
Build and Push Docker Image / docker (push) Has been cancelled

This commit is contained in:
Shav Kinderlehrer 2024-05-01 12:32:28 -04:00
parent 84f5f57ade
commit a4cfb64155
5 changed files with 13 additions and 6 deletions

2
Cargo.lock generated
View File

@ -215,7 +215,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "chela" name = "chela"
version = "1.3.0" version = "1.4.0"
dependencies = [ dependencies = [
"axum", "axum",
"chrono", "chrono",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "chela" name = "chela"
version = "1.3.0" version = "1.4.0"
edition = "2021" edition = "2021"
license = "BSL-1.0" license = "BSL-1.0"

View File

@ -71,6 +71,9 @@ If you would like Chela to listen for HTTP requests over a Unix socket, set this
##### `CHELA_ALPHABET` ##### `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. 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 ### Manually
#### Build #### Build
```bash ```bash
@ -94,7 +97,7 @@ If you would prefer to be the only one able to access these pages, then you can
```nginx ```nginx
server { server {
server_name example.com; server_name a.com;
location / { location / {
proxy_pass http://localhost:3000; proxy_pass http://localhost:3000;
@ -108,7 +111,6 @@ server {
location /tracking { location /tracking {
proxy_pass http://localhost:3000$request_uri; proxy_pass http://localhost:3000$request_uri;
proxy_set_header X-Real-IP $remote_addr;
auth_basic 'Restricted'; auth_basic 'Restricted';
auth_basic_user_file /path/to/your/.htpasswd; auth_basic_user_file /path/to/your/.htpasswd;

View File

@ -29,6 +29,7 @@ pub struct ServerState {
pub sqids: Sqids, pub sqids: Sqids,
pub main_page_redirect: Option<Url>, pub main_page_redirect: Option<Url>,
pub behind_proxy: bool, pub behind_proxy: bool,
pub uses_https: bool,
} }
#[derive(Debug, Clone, sqlx::FromRow, PartialEq, Eq)] #[derive(Debug, Clone, sqlx::FromRow, PartialEq, Eq)]
@ -87,12 +88,14 @@ async fn main() -> eyre::Result<()> {
.build()?; .build()?;
let main_page_redirect = env::var("CHELA_MAIN_PAGE_REDIRECT").unwrap_or_default(); let main_page_redirect = env::var("CHELA_MAIN_PAGE_REDIRECT").unwrap_or_default();
let behind_proxy = env::var("CHELA_BEHIND_PROXY").is_ok(); let behind_proxy = env::var("CHELA_BEHIND_PROXY").is_ok();
let uses_https = env::var("CHELA_USES_HTTPS").is_ok();
let server_state = ServerState { let server_state = ServerState {
db_pool, db_pool,
host, host,
sqids, sqids,
main_page_redirect: Url::parse(&main_page_redirect).ok(), main_page_redirect: Url::parse(&main_page_redirect).ok(),
behind_proxy, behind_proxy,
uses_https
}; };
serve(server_state).await?; serve(server_state).await?;

View File

@ -32,7 +32,8 @@ pub async fn create_link(
if id.exists { if id.exists {
log!("Serving cached id {} -> {}", id.id, form.url.as_str()); log!("Serving cached id {} -> {}", id.id, form.url.as_str());
return Html(format!( 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, state.host,
id.id, id.id,
form.url.as_str(), form.url.as_str(),
@ -72,7 +73,8 @@ VALUES ($1,$2,true)
return ( return (
StatusCode::OK, StatusCode::OK,
Html(format!( Html(format!(
r#"<pre>http://{}/{} -> <a href="{}"">{}</a></pre>"#, r#"<pre>http{}://{}/{} -> <a href="{}"">{}</a></pre>"#,
if state.uses_https { "s" } else { "" },
state.host, state.host,
id.id, id.id,
form.url.as_str(), form.url.as_str(),