chore: clean web example
This commit is contained in:
parent
60e32eb7bd
commit
e844d8d3e2
3 changed files with 19 additions and 19 deletions
|
@ -13,5 +13,5 @@ pub mod config;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
mod db;
|
pub mod db;
|
||||||
pub mod rest;
|
pub mod rest;
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
use web_example::config::load_env_config;
|
use web_example::config::load_env_config;
|
||||||
|
use web_example::db::persistence::create_postgres_pool;
|
||||||
use web_example::error::StdResult;
|
use web_example::error::StdResult;
|
||||||
use web_example::rest::server::start_server;
|
use web_example::rest::server::start_server;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> StdResult<()> {
|
async fn main() -> StdResult<()> {
|
||||||
load_env_config();
|
load_env_config();
|
||||||
start_server().await?;
|
|
||||||
|
let pool = create_postgres_pool().await;
|
||||||
|
start_server(pool).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use super::server_utils;
|
use super::server_utils;
|
||||||
use crate::config;
|
use crate::config;
|
||||||
use crate::db::persistence::create_postgres_pool;
|
use crate::db::persistence::PostgresPool;
|
||||||
use crate::error::SyncStdError;
|
use crate::error::SyncStdError;
|
||||||
use crate::rest::context::{RestGlobalContext, RestReqContext};
|
use crate::rest::context::{RestGlobalContext, RestReqContext};
|
||||||
use crate::rest::prelude::*;
|
use crate::rest::prelude::*;
|
||||||
|
@ -10,16 +10,7 @@ use hyper::service::{make_service_fn, service_fn};
|
||||||
use hyper::Server;
|
use hyper::Server;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// Waits for the Ctrl+C signal for graceful shutdown backend
|
pub async fn start_server(pool: PostgresPool) -> StdResult<()> {
|
||||||
async fn shutdown_signal() {
|
|
||||||
tokio::signal::ctrl_c()
|
|
||||||
.await
|
|
||||||
.expect("failed to install CTRL+C signal handler");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn start_server() -> StdResult<()> {
|
|
||||||
let pool = create_postgres_pool().await;
|
|
||||||
// let persistence = ood_persistence::bb8_postgres::new(&pool);
|
|
||||||
let context = Arc::new(RestGlobalContext { pool });
|
let context = Arc::new(RestGlobalContext { pool });
|
||||||
|
|
||||||
let new_service = make_service_fn(move |_| {
|
let new_service = make_service_fn(move |_| {
|
||||||
|
@ -42,11 +33,11 @@ pub async fn start_server() -> StdResult<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn split_request_uri_path(uri_path: &str) -> Vec<&str> {
|
/// Waits for the Ctrl+C signal for graceful shutdown backend
|
||||||
uri_path
|
async fn shutdown_signal() {
|
||||||
.split('/')
|
tokio::signal::ctrl_c()
|
||||||
.filter(|part| !part.is_empty())
|
.await
|
||||||
.collect()
|
.expect("failed to install CTRL+C signal handler");
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn process_request(
|
async fn process_request(
|
||||||
|
@ -70,7 +61,6 @@ async fn process_request(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
RestResponseData::<serde_json::Value>::error(REST_INTERNAL_SERVER_ERROR),
|
RestResponseData::<serde_json::Value>::error(REST_INTERNAL_SERVER_ERROR),
|
||||||
)
|
)
|
||||||
// TODO(pleshevskiy): investigate why `Send` is not implemented
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Ok(res) => res,
|
Ok(res) => res,
|
||||||
};
|
};
|
||||||
|
@ -93,3 +83,10 @@ async fn process_request(
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn split_request_uri_path(uri_path: &str) -> Vec<&str> {
|
||||||
|
uri_path
|
||||||
|
.split('/')
|
||||||
|
.filter(|part| !part.is_empty())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
Reference in a new issue