Skip to content

mutliple custom hosts #285

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/NavFiber.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
export let host = "";
let link = host ? `https://${host}` : "http://localhost:8001";
if ($stack && $stack.custom_2b_domain) {
link = `https://${$stack.custom_2b_domain}`;
const first = $stack.custom_2b_domain.split(",")[0];
link = `https://${first}`;
}

let toggled = false;
Expand Down
16 changes: 9 additions & 7 deletions src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,15 @@ pub fn create_super_user() -> User {
}

//get swarm host
let mut my_domain = getenv("NAV_BOLTWALL_SHARED_HOST").unwrap_or("".to_string());

if my_domain.is_empty() {
my_domain = getenv("HOST").unwrap_or("".to_string())
}
let my_domain = getenv("NAV_BOLTWALL_SHARED_HOST").unwrap_or("".to_string());
let host = if my_domain.is_empty() {
getenv("HOST").unwrap_or("".to_string())
} else {
let my_domain_split = my_domain.split(",").collect::<Vec<&str>>();
my_domain_split.get(0).unwrap_or(&"").to_string()
};

if my_domain.is_empty() {
if host.is_empty() {
log::error!("HOST {}", &error_msg);
return;
}
Expand All @@ -243,7 +245,7 @@ pub fn create_super_user() -> User {
let body = SendSwarmDetailsBody {
username: "super".to_string(),
password: password_,
host: my_domain,
host: host,
};

match client
Expand Down
9 changes: 6 additions & 3 deletions src/images/boltwall.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::traefik::{navfiber_boltwall_shared_host, traefik_labels};
use super::traefik::{navfiber_boltwall_shared_hosts, traefik_labels};
use super::*;
use crate::config::Node;
use crate::conn::lnd::utils::{dl_cert_to_base64, dl_macaroon};
Expand Down Expand Up @@ -56,8 +56,11 @@ impl BoltwallImage {
}
// boltwall host is on the vanity address /api
pub fn get_host(&self) -> Option<String> {
if let Some(sh) = navfiber_boltwall_shared_host() {
return Some(format!("{}/api", sh));
if let Some(sh) = navfiber_boltwall_shared_hosts() {
return match sh.first() {
Some(h) => Some(format!("{}/api", h)),
None => None,
};
}
self.host.clone()
}
Expand Down
27 changes: 19 additions & 8 deletions src/images/traefik.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,29 @@ pub fn traefik_labels(
format!("traefik.http.routers.{}.tls.certresolver=myresolver", name),
format!("traefik.http.routers.{}.entrypoints=websecure", name),
];
if navfiber_boltwall_shared_host().is_some() && is_navfiber_or_boltwall(name) {
let shared_host = navfiber_boltwall_shared_host().unwrap();
if navfiber_boltwall_shared_hosts().is_some() && is_navfiber_or_boltwall(name) {
let shared_hosts = navfiber_boltwall_shared_hosts().unwrap();
let mut shared_host_string = "Host(".to_string();
for (i, sh) in shared_hosts.iter().enumerate() {
let is_last = i == shared_hosts.len() - 1;
shared_host_string.push_str(&format!("`{}`", sh));
if !is_last {
shared_host_string.push_str(",");
}
}
shared_host_string.push_str(")");
if name == "navfiber" {
// anything except /api (local resources)
def.push(format!(
"traefik.http.routers.{}.rule=Host(`{}`)",
name, shared_host
"traefik.http.routers.{}.rule={}",
name, shared_host_string
));
def.push(format!("traefik.http.routers.{}.priority=1", name));
} else {
// if /api then all should go here
def.push(format!(
"traefik.http.routers.{}.rule=Host(`{}`) && (PathPrefix(`/api`) || PathPrefix(`/socket.io`))",
name, shared_host
"traefik.http.routers.{}.rule={} && (PathPrefix(`/api`) || PathPrefix(`/socket.io`))",
name, shared_host_string
));
def.push(format!("traefik.http.routers.{}.priority=2", name));
}
Expand All @@ -175,13 +184,15 @@ pub fn traefik_labels(
fn is_navfiber_or_boltwall(name: &str) -> bool {
name == "navfiber" || name == "boltwall"
}
pub fn navfiber_boltwall_shared_host() -> Option<String> {
// always will have at least one element of non-empty string if its Some
pub fn navfiber_boltwall_shared_hosts() -> Option<Vec<String>> {
let sh = std::env::var("NAV_BOLTWALL_SHARED_HOST").ok();
match sh {
Some(h) => {
// remove empty string
if h.len() > 0 {
Some(h)
let hts = h.split(",").into_iter().map(|s| s.to_string()).collect();
Some(hts)
} else {
None
}
Expand Down