1pub mod reader_route;
5pub mod stream_sse;
6
7use axum::Router;
8use axum::routing::{get, post};
9use std::sync::Arc;
10
11use crate::engine::Engine;
12pub use reader_route::{handle_jina_get, handle_jina_post};
13pub use stream_sse::stream_markdown_sse;
14
15pub fn jina_router(engine: Arc<dyn Engine>) -> Router {
17 Router::new()
18 .route("/r/{*url}", get(handle_jina_get))
19 .route("/r", post(handle_jina_post))
20 .route("/r/", post(handle_jina_post))
21 .with_state(engine)
22}
23
24#[cfg(test)]
25mod tests {
26 use super::*;
27
28 #[test]
29 fn test_sse_event_formatting() {
30 let resp = stream_markdown_sse(
31 "https://example.com",
32 Some("Test Title"),
33 "# Hello\n\nWorld paragraph",
34 );
35 assert_eq!(resp.status(), axum::http::StatusCode::OK);
36 assert_eq!(
37 resp.headers().get("content-type").unwrap(),
38 "text/event-stream; charset=utf-8"
39 );
40 }
41}