1pub mod cache;
2pub mod config;
3pub mod control;
4pub mod proxy;
5
6use axum::Router;
7use cache::{CacheStore, RefreshTrigger};
8use proxy::ProxyState;
9use std::sync::Arc;
10
11pub fn create_proxy(proxy_url: String) -> (Router, RefreshTrigger) {
14 let refresh_trigger = RefreshTrigger::new();
15 let cache = CacheStore::new(refresh_trigger.clone());
16
17 let proxy_state = Arc::new(ProxyState::new(cache, proxy_url));
18
19 let app = Router::new()
20 .fallback(proxy::proxy_handler)
21 .with_state(proxy_state);
22
23 (app, refresh_trigger)
24}
25
26pub fn create_proxy_with_trigger(proxy_url: String, refresh_trigger: RefreshTrigger) -> Router {
28 let cache = CacheStore::new(refresh_trigger);
29 let proxy_state = Arc::new(ProxyState::new(cache, proxy_url));
30
31 Router::new()
32 .fallback(proxy::proxy_handler)
33 .with_state(proxy_state)
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn test_create_proxy() {
42 let (_app, trigger) = create_proxy("http://localhost:8080".to_string());
43 trigger.trigger();
44 }
46}