-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add backend support for alternate base dir (subdir/subpath) hosting #868
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
use std::process::exit; | ||
use std::sync::RwLock; | ||
|
||
use reqwest::Url; | ||
|
||
use crate::error::Error; | ||
use crate::util::{get_env, get_env_bool}; | ||
|
||
|
@@ -240,6 +242,10 @@ make_config! { | |
domain: String, true, def, "http://localhost".to_string(); | ||
/// Domain Set |> Indicates if the domain is set by the admin. Otherwise the default will be used. | ||
domain_set: bool, false, def, false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, domain_set is a bit special cased here: |
||
/// Domain origin |> Domain URL origin (in https://example.com:8443/path, https://example.com:8443 is the origin) | ||
domain_origin: String, false, auto, |c| extract_url_origin(&c.domain); | ||
/// Domain path |> Domain URL path (in https://example.com:8443/path, /path is the path) | ||
domain_path: String, false, auto, |c| extract_url_path(&c.domain); | ||
/// Enable web vault | ||
web_vault_enabled: bool, false, def, true; | ||
|
||
|
@@ -457,6 +463,21 @@ fn validate_config(cfg: &ConfigItems) -> Result<(), Error> { | |
Ok(()) | ||
} | ||
|
||
/// Extracts an RFC 6454 web origin from a URL. | ||
fn extract_url_origin(url: &str) -> String { | ||
let url = Url::parse(url).expect("valid URL"); | ||
|
||
url.origin().ascii_serialization() | ||
} | ||
|
||
/// Extracts the path from a URL. | ||
/// All trailing '/' chars are trimmed, even if the path is a lone '/'. | ||
fn extract_url_path(url: &str) -> String { | ||
let url = Url::parse(url).expect("valid URL"); | ||
|
||
url.path().trim_end_matches('/').to_string() | ||
} | ||
|
||
impl Config { | ||
pub fn load() -> Result<Self, Error> { | ||
// Loading from env and file | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to
domain_origin()
instead ofdomain()
to avoid JWT encode/decode issues in case the installation is moved to a different base dir. Note that in the usual case where the backend is hosted at the root of the domain,domain_origin()
anddomain()
should be identical.