Move app state
This commit is contained in:
parent
cd7fe5fe39
commit
0943681702
7 changed files with 15 additions and 20 deletions
|
|
@ -1,12 +1,11 @@
|
||||||
mod app_state;
|
|
||||||
mod config;
|
mod config;
|
||||||
mod consts;
|
mod consts;
|
||||||
mod database;
|
mod database;
|
||||||
mod errors;
|
mod errors;
|
||||||
mod server;
|
mod server;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
use app_state::AppState;
|
|
||||||
use errors::{init_error, SyncServerError};
|
use errors::{init_error, SyncServerError};
|
||||||
use log::info;
|
use log::info;
|
||||||
use server::create_server;
|
use server::create_server;
|
||||||
|
|
@ -34,12 +33,7 @@ async fn main() -> Result<(), SyncServerError> {
|
||||||
env!("CARGO_PKG_VERSION")
|
env!("CARGO_PKG_VERSION")
|
||||||
);
|
);
|
||||||
|
|
||||||
let app_state = AppState::try_new()
|
create_server()
|
||||||
.await
|
|
||||||
.context("Failed to initialise app state")
|
|
||||||
.map_err(init_error)?;
|
|
||||||
|
|
||||||
create_server(app_state)
|
|
||||||
.await
|
.await
|
||||||
.context("Failed to start server")
|
.context("Failed to start server")
|
||||||
.map_err(init_error)
|
.map_err(init_error)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use aide::{
|
||||||
transform::TransformOpenApi,
|
transform::TransformOpenApi,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Context as _, Result};
|
use anyhow::{anyhow, Context as _, Result};
|
||||||
|
use app_state::AppState;
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{DefaultBodyLimit, Request},
|
extract::{DefaultBodyLimit, Request},
|
||||||
http::{self, HeaderValue, Method},
|
http::{self, HeaderValue, Method},
|
||||||
|
|
@ -28,10 +29,8 @@ use tower_http::{
|
||||||
};
|
};
|
||||||
use tracing::{info_span, Level};
|
use tracing::{info_span, Level};
|
||||||
|
|
||||||
use crate::{
|
use crate::errors::{not_found_error, SerializedError};
|
||||||
app_state::AppState,
|
mod app_state;
|
||||||
errors::{not_found_error, SerializedError},
|
|
||||||
};
|
|
||||||
mod auth;
|
mod auth;
|
||||||
mod create_document;
|
mod create_document;
|
||||||
mod delete_document;
|
mod delete_document;
|
||||||
|
|
@ -42,10 +41,14 @@ mod requests;
|
||||||
mod responses;
|
mod responses;
|
||||||
mod update_document;
|
mod update_document;
|
||||||
|
|
||||||
pub async fn create_server(app_state: AppState) -> Result<()> {
|
pub async fn create_server() -> Result<()> {
|
||||||
aide::gen::on_error(|err| error!("{err}"));
|
aide::gen::on_error(|err| error!("{err}"));
|
||||||
aide::gen::extract_schemas(true);
|
aide::gen::extract_schemas(true);
|
||||||
|
|
||||||
|
let app_state = AppState::try_new()
|
||||||
|
.await
|
||||||
|
.context("Failed to initialise app state")?;
|
||||||
|
|
||||||
let address = format!(
|
let address = format!(
|
||||||
"{}:{}",
|
"{}:{}",
|
||||||
&app_state.config.server.host, &app_state.config.server.port
|
&app_state.config.server.host, &app_state.config.server.port
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
|
use super::app_state::AppState;
|
||||||
use crate::{
|
use crate::{
|
||||||
app_state::AppState,
|
|
||||||
config::user_config::User,
|
config::user_config::User,
|
||||||
errors::{unauthorized_error, SyncServerError},
|
errors::{unauthorized_error, SyncServerError},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,8 @@ use axum_extra::{
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use super::auth::auth;
|
use super::{app_state::AppState, auth::auth};
|
||||||
use crate::{
|
use crate::{
|
||||||
app_state::AppState,
|
|
||||||
database::models::{DocumentId, DocumentVersion, VaultId},
|
database::models::{DocumentId, DocumentVersion, VaultId},
|
||||||
errors::{not_found_error, server_error, SyncServerError},
|
errors::{not_found_error, server_error, SyncServerError},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,8 @@ use axum_extra::{
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use super::{auth::auth, responses::FetchLatestDocumentsResponse};
|
use super::{app_state::AppState, auth::auth, responses::FetchLatestDocumentsResponse};
|
||||||
use crate::{
|
use crate::{
|
||||||
app_state::AppState,
|
|
||||||
database::models::{VaultId, VaultUpdateId},
|
database::models::{VaultId, VaultUpdateId},
|
||||||
errors::{server_error, SyncServerError},
|
errors::{server_error, SyncServerError},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ use axum_extra::{
|
||||||
TypedHeader,
|
TypedHeader,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{auth::auth, responses::PingResponse};
|
use super::{app_state::AppState, auth::auth, responses::PingResponse};
|
||||||
use crate::{app_state::AppState, errors::SyncServerError};
|
use crate::errors::SyncServerError;
|
||||||
|
|
||||||
#[axum::debug_handler]
|
#[axum::debug_handler]
|
||||||
pub async fn ping(
|
pub async fn ping(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue