2021-04-15 22:32:05 +02:00
|
|
|
fn main() {
|
2021-10-08 09:38:10 +02:00
|
|
|
if std::fs::metadata("./src/location.rs").is_ok() {
|
|
|
|
return;
|
|
|
|
}
|
2021-04-15 22:32:05 +02:00
|
|
|
if let Ok(contents) = std::fs::read_to_string("../.env") {
|
|
|
|
for line in contents.lines() {
|
|
|
|
if line.starts_with('#') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let parts: Vec<&str> = line.split('=').collect();
|
|
|
|
match (parts.get(0), parts.get(1)) {
|
|
|
|
(Some(k), Some(v)) => std::env::set_var(k, v),
|
|
|
|
_ => continue,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-04 17:14:31 +02:00
|
|
|
let addr = std::env::var("BITQUE_SERVER_BIND").unwrap_or_else(|_| "0.0.0.0".to_string());
|
2021-04-15 22:32:05 +02:00
|
|
|
let addr = if addr.as_str() == "0.0.0.0" || addr.as_str() == "localhost" {
|
|
|
|
"localhost"
|
|
|
|
} else {
|
|
|
|
addr.as_str()
|
|
|
|
}
|
|
|
|
.to_string();
|
2023-04-04 17:14:31 +02:00
|
|
|
let port = std::env::var("BITQUE_SERVER_PORT").unwrap_or_else(|_| "80".to_string());
|
2021-04-15 22:32:05 +02:00
|
|
|
let port = match port.as_str() {
|
|
|
|
"80" | "8080" | "443" => "".to_string(),
|
|
|
|
_ => format!(":{}", port),
|
|
|
|
};
|
|
|
|
let addr = format!("{}{}", addr, port);
|
|
|
|
|
|
|
|
std::fs::write(
|
|
|
|
"./src/location.rs",
|
|
|
|
format!(
|
|
|
|
"
|
|
|
|
pub fn host_url() -> &'static str {{
|
|
|
|
if cfg!(debug_assertions) {{
|
|
|
|
\"http://{addr}\"
|
|
|
|
}} else {{
|
|
|
|
\"https://{addr}\"
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
pub fn ws_url() -> &'static str {{
|
|
|
|
if cfg!(debug_assertions) {{
|
|
|
|
\"ws://{addr}/ws/\"
|
|
|
|
}} else {{
|
|
|
|
\"wss://{addr}/ws/\"
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
",
|
|
|
|
addr = addr
|
|
|
|
)
|
|
|
|
.trim(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
}
|