1
2
/*
2
 * This file is part of mailpot
3
 *
4
 * Copyright 2020 - Manos Pitsidianakis
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as
8
 * published by the Free Software Foundation, either version 3 of the
9
 * License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18
 */
19

            
20
pub use std::{net::SocketAddr, sync::Arc};
21

            
22
pub use axum::Router;
23
pub use http::header;
24
pub use log::{debug, info, trace};
25
pub use mailpot::{models::*, Configuration, Connection};
26
pub mod errors;
27
pub mod routes;
28
pub mod settings;
29

            
30
use tower_http::{
31
    compression::CompressionLayer, cors::CorsLayer, propagate_header::PropagateHeaderLayer,
32
    sensitive_headers::SetSensitiveHeadersLayer,
33
};
34

            
35
8
pub fn create_app(conf: Arc<Configuration>) -> Router {
36
56
    Router::new()
37
8
        .with_state(conf.clone())
38
8
        .merge(Router::new().nest("/v1", Router::new().merge(routes::list::create_route(conf))))
39
8
        .layer(SetSensitiveHeadersLayer::new(std::iter::once(
40
8
            header::AUTHORIZATION,
41
        )))
42
        // Compress responses
43
8
        .layer(CompressionLayer::new())
44
        // Propagate `X-Request-Id`s from requests to responses
45
8
        .layer(PropagateHeaderLayer::new(header::HeaderName::from_static(
46
            "x-request-id",
47
        )))
48
        // CORS configuration. This should probably be more restrictive in
49
        // production.
50
8
        .layer(CorsLayer::permissive())
51
8
}