@ -60,7 +60,7 @@ async fn main() -> std::io::Result<()> {
|
||||
PKG_NAME, PKG_DESCRIPTION, PKG_HOMEPAGE, VERSION, GIT_COMMIT_HASH
|
||||
);
|
||||
|
||||
println!("Starting server on: http://{}", SETTINGS.server.get_ip());
|
||||
println!("Starting server on: http://{}", SETTINGS.get_ip());
|
||||
|
||||
let data = Data::new();
|
||||
|
||||
@ -79,8 +79,8 @@ async fn main() -> std::io::Result<()> {
|
||||
.app_data(data.clone())
|
||||
.configure(routes::services)
|
||||
})
|
||||
.workers(SETTINGS.server.workers.unwrap_or_else(num_cpus::get))
|
||||
.bind(SETTINGS.server.get_ip())
|
||||
.workers(SETTINGS.workers.unwrap_or_else(num_cpus::get))
|
||||
.bind(SETTINGS.get_ip())
|
||||
.unwrap()
|
||||
.run()
|
||||
.await
|
||||
|
@ -133,7 +133,7 @@ const INDEX: &str = include_str!("../templates/index.html");
|
||||
async fn index() -> impl Responder {
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(INDEX.replace("SOURCE_CODE_REPLACE", &crate::SETTINGS.source_code))
|
||||
.body(INDEX)
|
||||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.asset")]
|
||||
|
@ -24,7 +24,9 @@ use serde::Deserialize;
|
||||
use url::Url;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Server {
|
||||
pub struct Settings {
|
||||
pub debug: bool,
|
||||
pub cache: Option<String>,
|
||||
pub port: u32,
|
||||
pub domain: String,
|
||||
pub ip: String,
|
||||
@ -32,28 +34,13 @@ pub struct Server {
|
||||
pub workers: Option<usize>,
|
||||
}
|
||||
|
||||
impl Server {
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
pub fn get_ip(&self) -> String {
|
||||
format!("{}:{}", self.ip, self.port)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Settings {
|
||||
pub debug: bool,
|
||||
pub cache: Option<String>,
|
||||
pub server: Server,
|
||||
pub source_code: String,
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
impl Settings {
|
||||
pub fn new() -> Result<Self, ConfigError> {
|
||||
let mut s = Config::builder();
|
||||
|
||||
// setting default values
|
||||
const CURRENT_DIR: &str = "./config/default.toml";
|
||||
const CURRENT_DIR: &str = "./config.toml";
|
||||
const ETC: &str = "/etc/libmedium/config.toml";
|
||||
|
||||
if let Ok(path) = env::var("LIBMEDIUM") {
|
||||
@ -105,4 +92,9 @@ impl Settings {
|
||||
fn check_url(&self) {
|
||||
Url::parse(&self.source_code).expect("Please enter a URL for source_code in settings");
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
pub fn get_ip(&self) -> String {
|
||||
format!("{}:{}", self.ip, self.port)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user