Lines
100 %
Functions
66.67 %
Branches
/*
* This file is part of mailpot
*
* Copyright 2020 - Manos Pitsidianakis
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
pub use std::{net::SocketAddr, sync::Arc};
pub use axum::Router;
pub use http::header;
pub use log::{debug, info, trace};
pub use mailpot::{models::*, Configuration, Connection};
pub mod errors;
pub mod routes;
pub mod settings;
use tower_http::{
compression::CompressionLayer, cors::CorsLayer, propagate_header::PropagateHeaderLayer,
sensitive_headers::SetSensitiveHeadersLayer,
};
pub fn create_app(conf: Arc<Configuration>) -> Router {
Router::new()
.with_state(conf.clone())
.merge(Router::new().nest("/v1", Router::new().merge(routes::list::create_route(conf))))
.layer(SetSensitiveHeadersLayer::new(std::iter::once(
header::AUTHORIZATION,
)))
// Compress responses
.layer(CompressionLayer::new())
// Propagate `X-Request-Id`s from requests to responses
.layer(PropagateHeaderLayer::new(header::HeaderName::from_static(
"x-request-id",
// CORS configuration. This should probably be more restrictive in
// production.
.layer(CorsLayer::permissive())
}