fix: fix production issues
This commit is contained in:
@@ -72,6 +72,11 @@ impl AppBuilder {
|
||||
}
|
||||
|
||||
pub async fn build(self) -> RecorderResult<App> {
|
||||
if self.working_dir != "." {
|
||||
std::env::set_current_dir(&self.working_dir)?;
|
||||
println!("set current dir to working dir: {}", self.working_dir);
|
||||
}
|
||||
|
||||
self.load_env().await?;
|
||||
|
||||
let config = self.load_config().await?;
|
||||
@@ -86,22 +91,12 @@ impl AppBuilder {
|
||||
}
|
||||
|
||||
pub async fn load_env(&self) -> RecorderResult<()> {
|
||||
AppConfig::load_dotenv(
|
||||
&self.environment,
|
||||
&self.working_dir,
|
||||
self.dotenv_file.as_deref(),
|
||||
)
|
||||
.await?;
|
||||
AppConfig::load_dotenv(&self.environment, self.dotenv_file.as_deref()).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn load_config(&self) -> RecorderResult<AppConfig> {
|
||||
let config = AppConfig::load_config(
|
||||
&self.environment,
|
||||
&self.working_dir,
|
||||
self.config_file.as_deref(),
|
||||
)
|
||||
.await?;
|
||||
let config = AppConfig::load_config(&self.environment, self.config_file.as_deref()).await?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
@@ -136,7 +131,7 @@ impl AppBuilder {
|
||||
}
|
||||
|
||||
pub fn working_dir_from_manifest_dir(self) -> Self {
|
||||
let manifest_dir = if cfg!(debug_assertions) || cfg!(test) {
|
||||
let manifest_dir = if cfg!(debug_assertions) || cfg!(test) || cfg!(feature = "playground") {
|
||||
env!("CARGO_MANIFEST_DIR")
|
||||
} else {
|
||||
"./apps/recorder"
|
||||
|
||||
@@ -55,8 +55,8 @@ impl AppConfig {
|
||||
format!(".{}.local", environment.full_name()),
|
||||
format!(".{}.local", environment.short_name()),
|
||||
String::from(".local"),
|
||||
environment.full_name().to_string(),
|
||||
environment.short_name().to_string(),
|
||||
format!(".{}", environment.full_name()),
|
||||
format!(".{}", environment.short_name()),
|
||||
String::from(""),
|
||||
]
|
||||
}
|
||||
@@ -88,13 +88,12 @@ impl AppConfig {
|
||||
|
||||
pub async fn load_dotenv(
|
||||
environment: &Environment,
|
||||
working_dir: &str,
|
||||
dotenv_file: Option<&str>,
|
||||
) -> RecorderResult<()> {
|
||||
let try_dotenv_file_or_dirs = if dotenv_file.is_some() {
|
||||
vec![dotenv_file]
|
||||
} else {
|
||||
vec![Some(working_dir)]
|
||||
vec![Some(".")]
|
||||
};
|
||||
|
||||
let priority_suffix = &AppConfig::priority_suffix(environment);
|
||||
@@ -111,11 +110,16 @@ impl AppConfig {
|
||||
for f in try_filenames.iter() {
|
||||
let p = try_dotenv_file_or_dir_path.join(f);
|
||||
if p.exists() && p.is_file() {
|
||||
println!("Loading dotenv file: {}", p.display());
|
||||
dotenvy::from_path(p)?;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if try_dotenv_file_or_dir_path.is_file() {
|
||||
println!(
|
||||
"Loading dotenv file: {}",
|
||||
try_dotenv_file_or_dir_path.display()
|
||||
);
|
||||
dotenvy::from_path(try_dotenv_file_or_dir_path)?;
|
||||
break;
|
||||
}
|
||||
@@ -127,13 +131,12 @@ impl AppConfig {
|
||||
|
||||
pub async fn load_config(
|
||||
environment: &Environment,
|
||||
working_dir: &str,
|
||||
config_file: Option<&str>,
|
||||
) -> RecorderResult<AppConfig> {
|
||||
let try_config_file_or_dirs = if config_file.is_some() {
|
||||
vec![config_file]
|
||||
} else {
|
||||
vec![Some(working_dir)]
|
||||
vec![Some(".")]
|
||||
};
|
||||
|
||||
let allowed_extensions = &AppConfig::allowed_extension();
|
||||
@@ -159,6 +162,7 @@ impl AppConfig {
|
||||
let p = try_config_file_or_dir_path.join(f);
|
||||
if p.exists() && p.is_file() {
|
||||
fig = AppConfig::merge_provider_from_file(fig, &p, ext)?;
|
||||
println!("Loaded config file: {}", p.display());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -169,6 +173,10 @@ impl AppConfig {
|
||||
{
|
||||
fig =
|
||||
AppConfig::merge_provider_from_file(fig, try_config_file_or_dir_path, ext)?;
|
||||
println!(
|
||||
"Loaded config file: {}",
|
||||
try_config_file_or_dir_path.display()
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use std::{net::SocketAddr, sync::Arc};
|
||||
|
||||
use axum::Router;
|
||||
use axum::{Router, middleware::from_fn_with_state};
|
||||
use tokio::{net::TcpSocket, signal};
|
||||
use tower_http::services::{ServeDir, ServeFile};
|
||||
use tracing::instrument;
|
||||
|
||||
use super::{builder::AppBuilder, context::AppContextTrait};
|
||||
use crate::{
|
||||
auth::webui_auth_middleware,
|
||||
errors::{RecorderError, RecorderResult},
|
||||
web::{
|
||||
controller::{self, core::ControllerTrait},
|
||||
@@ -58,13 +60,19 @@ impl App {
|
||||
controller::oidc::create(context.clone()),
|
||||
controller::metadata::create(context.clone()),
|
||||
controller::r#static::create(context.clone()),
|
||||
controller::feeds::create(context.clone()),
|
||||
controller::feeds::create(context.clone())
|
||||
)?;
|
||||
|
||||
for c in [graphql_c, oidc_c, metadata_c, static_c, feeds_c] {
|
||||
router = c.apply_to(router);
|
||||
}
|
||||
|
||||
router = router
|
||||
.fallback_service(
|
||||
ServeDir::new("webui").not_found_service(ServeFile::new("webui/index.html")),
|
||||
)
|
||||
.layer(from_fn_with_state(context.clone(), webui_auth_middleware));
|
||||
|
||||
let middlewares = default_middleware_stack(context.clone());
|
||||
for mid in middlewares {
|
||||
if mid.is_enabled() {
|
||||
|
||||
Reference in New Issue
Block a user