create_proxy

Function create_proxy 

Source
pub fn create_proxy(proxy_url: String) -> (Router, RefreshTrigger)
Expand description

The main library interface for using phantom-frame as a library Returns a proxy handler function and a refresh trigger

Examples found in repository?
examples/library_usage.rs (line 11)
5async fn main() {
6    // Initialize tracing (optional but recommended)
7    // tracing_subscriber::fmt::init();
8
9    // Create proxy - proxy_url is the backend server to proxy requests to
10    let (proxy_app, refresh_trigger): (Router, RefreshTrigger) =
11        create_proxy("http://localhost:8080".to_string());
12
13    // You can clone and use the refresh_trigger in your code
14    let trigger_clone = refresh_trigger.clone();
15
16    // Example: Trigger cache refresh from another part of your application
17    tokio::spawn(async move {
18        tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
19        trigger_clone.trigger();
20        println!("Cache refreshed!");
21    });
22
23    // Start the proxy server
24    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
25
26    println!("Proxy server listening on http://0.0.0.0:3000");
27
28    axum::serve(listener, proxy_app).await.unwrap();
29}