mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 09:07:09 +08:00
Testability ddd repository (#55)
This commit is contained in:
@ -30,13 +30,18 @@ pub mod env;
|
||||
pub mod pii;
|
||||
pub mod routes;
|
||||
pub mod scheduler;
|
||||
|
||||
#[allow(unused_imports)] // Allow unused imports only for schema module
|
||||
pub mod schema;
|
||||
pub mod services;
|
||||
pub mod types;
|
||||
pub mod utils;
|
||||
|
||||
use actix_web::{dev::Server, middleware::ErrorHandlers};
|
||||
use actix_web::{
|
||||
body::MessageBody,
|
||||
dev::{Server, ServiceFactory, ServiceRequest},
|
||||
middleware::ErrorHandlers,
|
||||
};
|
||||
use http::StatusCode;
|
||||
use routes::AppState;
|
||||
|
||||
@ -44,7 +49,6 @@ pub use self::env::logger;
|
||||
use crate::{
|
||||
configs::settings::Settings,
|
||||
core::errors::{self, BachResult},
|
||||
services::Store,
|
||||
};
|
||||
|
||||
/// Header Constants
|
||||
@ -54,6 +58,54 @@ pub mod headers {
|
||||
pub const X_ROUTER: &str = "X-router";
|
||||
pub const AUTHORIZATION: &str = "Authorization";
|
||||
}
|
||||
|
||||
pub fn mk_app(
|
||||
state: AppState,
|
||||
request_body_limit: usize,
|
||||
) -> actix_web::App<
|
||||
impl ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = actix_web::dev::ServiceResponse<impl MessageBody>,
|
||||
Error = actix_web::Error,
|
||||
InitError = (),
|
||||
>,
|
||||
> {
|
||||
let json_cfg = actix_web::web::JsonConfig::default()
|
||||
.limit(request_body_limit)
|
||||
.content_type_required(true)
|
||||
.content_type(|mime| mime == mime::APPLICATION_JSON) // FIXME: This doesn't seem to be enforced.
|
||||
.error_handler(utils::error_parser::custom_json_error_handler);
|
||||
|
||||
let mut server_app = actix_web::App::new()
|
||||
.app_data(json_cfg)
|
||||
.wrap(router_env::tracing_actix_web::TracingLogger::default())
|
||||
.wrap(ErrorHandlers::new().handler(
|
||||
StatusCode::NOT_FOUND,
|
||||
errors::error_handlers::custom_error_handlers,
|
||||
))
|
||||
.wrap(ErrorHandlers::new().handler(
|
||||
StatusCode::METHOD_NOT_ALLOWED,
|
||||
errors::error_handlers::custom_error_handlers,
|
||||
))
|
||||
.wrap(cors::cors())
|
||||
.service(routes::Payments::server(state.clone()))
|
||||
.service(routes::Customers::server(state.clone()))
|
||||
.service(routes::Refunds::server(state.clone()))
|
||||
.service(routes::Payouts::server(state.clone()))
|
||||
.service(routes::PaymentMethods::server(state.clone()))
|
||||
.service(routes::MerchantAccount::server(state.clone()))
|
||||
.service(routes::MerchantConnectorAccount::server(state.clone()))
|
||||
.service(routes::Webhooks::server(state.clone()));
|
||||
|
||||
#[cfg(feature = "stripe")]
|
||||
{
|
||||
server_app = server_app.service(routes::StripeApis::server(state.clone()));
|
||||
}
|
||||
server_app = server_app.service(routes::Health::server(state));
|
||||
server_app
|
||||
}
|
||||
|
||||
#[allow(clippy::expect_used, clippy::unwrap_used)]
|
||||
/// # Panics
|
||||
///
|
||||
@ -62,53 +114,13 @@ pub async fn start_server(conf: Settings) -> BachResult<(Server, AppState)> {
|
||||
logger::debug!(startup_config=?conf);
|
||||
|
||||
let server = conf.server.clone();
|
||||
let state = routes::AppState {
|
||||
flow_name: String::from("default"),
|
||||
store: Store::new(&conf).await,
|
||||
conf,
|
||||
};
|
||||
let state = routes::AppState::new(conf).await;
|
||||
// Cloning to close connections before shutdown
|
||||
let app_state = state.clone();
|
||||
|
||||
let request_body_limit = server.request_body_limit;
|
||||
|
||||
let server = actix_web::HttpServer::new(move || {
|
||||
let json_cfg = actix_web::web::JsonConfig::default()
|
||||
.limit(request_body_limit)
|
||||
.content_type_required(true)
|
||||
.content_type(|mime| mime == mime::APPLICATION_JSON) // FIXME: This doesn't seem to be enforced.
|
||||
.error_handler(utils::error_parser::custom_json_error_handler);
|
||||
|
||||
let mut server_app = actix_web::App::new()
|
||||
.app_data(json_cfg)
|
||||
.wrap(router_env::tracing_actix_web::TracingLogger::default())
|
||||
.wrap(ErrorHandlers::new().handler(
|
||||
StatusCode::NOT_FOUND,
|
||||
errors::error_handlers::custom_error_handlers,
|
||||
))
|
||||
.wrap(ErrorHandlers::new().handler(
|
||||
StatusCode::METHOD_NOT_ALLOWED,
|
||||
errors::error_handlers::custom_error_handlers,
|
||||
))
|
||||
.wrap(cors::cors())
|
||||
.service(routes::Payments::server(state.clone()))
|
||||
.service(routes::Customers::server(state.clone()))
|
||||
.service(routes::Refunds::server(state.clone()))
|
||||
.service(routes::Payouts::server(state.clone()))
|
||||
.service(routes::PaymentMethods::server(state.clone()))
|
||||
.service(routes::MerchantAccount::server(state.clone()))
|
||||
.service(routes::MerchantConnectorAccount::server(state.clone()))
|
||||
.service(routes::Webhooks::server(state.clone()));
|
||||
|
||||
#[cfg(feature = "stripe")]
|
||||
{
|
||||
server_app = server_app.service(routes::StripeApis::server(state.clone()));
|
||||
}
|
||||
server_app = server_app.service(routes::Health::server(state.clone()));
|
||||
server_app
|
||||
})
|
||||
.bind((server.host.as_str(), server.port))?
|
||||
.run();
|
||||
let server = actix_web::HttpServer::new(move || mk_app(state.clone(), request_body_limit))
|
||||
.bind((server.host.as_str(), server.port))?
|
||||
.run();
|
||||
|
||||
Ok((server, app_state))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user