• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polyphony-chat / sonata / 16250718729

13 Jul 2025 03:34PM UTC coverage: 63.362% (-16.7%) from 80.109%
16250718729

push

github

bitfl0wer
feat(squashme): Further work on register endpoint with TODOs

9 of 20 branches covered (45.0%)

Branch coverage included in aggregate %.

0 of 12 new or added lines in 1 file covered. (0.0%)

28 existing lines in 7 files now uncovered.

285 of 444 relevant lines covered (64.19%)

418.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/api/mod.rs
1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4

5
use log::info;
6
use poem::{
7
        EndpointExt, IntoResponse, Response, Route, Server, handler,
8
        http::{Method, StatusCode},
9
        listener::TcpListener,
10
        middleware::{Cors, NormalizePath},
11
        web::Json,
12
};
13
use serde_json::json;
14

15
use crate::{
16
        config::ApiConfig,
17
        database::{Database, tokens::TokenStore},
18
};
19

20
/// Admin-only functionality.
21
pub(super) mod admin;
22
/// Authentication functionality.
23
mod auth;
24
/// Custom middlewares, such as authentication and active-user.
25
pub(crate) mod middlewares;
26
pub(crate) mod models;
27

28
#[allow(clippy::expect_used)]
29
#[cfg_attr(coverage_nightly, coverage(off))]
30
/// Build the API [Route]s and start a `tokio::task`, which is a poem [Server]
31
/// processing incoming HTTP API requests.
32
pub(super) fn start_api(
33
        api_config: ApiConfig,
34
        db: Database,
35
        token_store: TokenStore,
36
) -> tokio::task::JoinHandle<()> {
37
        let routes = Route::new()
38
                .at("/healthz", healthz)
39
                .nest("/.p2/core/", setup_p2_core_routes())
40
                .with(NormalizePath::new(poem::middleware::TrailingSlash::Trim))
41
                .with(Cors::new().allow_methods(&[
42
                        Method::CONNECT,
43
                        Method::GET,
44
                        Method::POST,
45
                        Method::PUT,
46
                        Method::DELETE,
47
                        Method::PATCH,
48
                        Method::OPTIONS,
49
                ]))
50
                .catch_all_error(custom_error)
51
                .data(db)
52
                .data(token_store);
53

54
        let handle = tokio::task::spawn(async move {
55
                Server::new(TcpListener::bind((api_config.host.as_str().trim(), api_config.port)))
56
                        .run(routes)
57
                        .await
58
                        .expect("Failed to start HTTP server");
59
                log::info!("HTTP Server stopped");
60
        });
61
        info!("Started HTTP API server");
62
        handle
63
}
64

65
/// Catch-all fallback error.
66
async fn custom_error(err: poem::Error) -> impl IntoResponse {
×
UNCOV
67
        Json(json! ({
×
UNCOV
68
                "success": false,
×
69
                "message": err.to_string(),
×
70
        }))
×
71
        .with_status(err.status())
×
UNCOV
72
}
×
73

74
#[handler]
75
fn healthz() -> impl IntoResponse {
×
76
        Response::builder().status(StatusCode::OK).finish()
×
UNCOV
77
}
×
78

79
/// All routes under `/.p2/core/`.
UNCOV
80
fn setup_p2_core_routes() -> Route {
×
UNCOV
81
        Route::new()
×
UNCOV
82
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc