fn router(state: Arc<State>, cfg: Arc<RtcServe>) -> Router<BoxRoute> {
    // Build static file server, middleware, error handler & WS route for reloads.
    let mut router = Router::new()
        .nest(&state.public_url, get(serve_dist.layer(TraceLayer::new_for_http())))
        .route(
            "/_trunk/ws",
            get(|ws: WebSocketUpgrade, state: Extension<Arc<State>>| async move {
                ws.on_upgrade(|socket| async move { handle_ws(socket, state.0).await })
            }),
        )
        .layer(AddExtensionLayer::new(state.clone()))
        .boxed();

    tracing::info!("{} serving static assets at -> {}", SERVER, state.public_url.as_str());

    // Build proxies.
    if let Some(backend) = &cfg.proxy_backend {
        if cfg.proxy_ws {
            let handler = ProxyHandlerWebSocket::new(backend.clone(), cfg.proxy_rewrite.clone());
            router = handler.clone().register(router);
            tracing::info!("{} proxying websocket {} -> {}", SERVER, handler.path(), &backend);
        } else {
            let handler = ProxyHandlerHttp::new(state.client.clone(), backend.clone(), cfg.proxy_rewrite.clone());
            router = handler.clone().register(router);
            tracing::info!("{} proxying {} -> {}", SERVER, handler.path(), &backend);
        }
    } else if let Some(proxies) = &cfg.proxies {
        for proxy in proxies.iter() {
            if proxy.ws {
                let handler = ProxyHandlerWebSocket::new(proxy.backend.clone(), proxy.rewrite.clone());
                router = handler.clone().register(router);
                tracing::info!("{} proxying websocket {} -> {}", SERVER, handler.path(), &proxy.backend);
            } else {
                let handler = ProxyHandlerHttp::new(state.client.clone(), proxy.backend.clone(), proxy.rewrite.clone());
                router = handler.clone().register(router);
                tracing::info!("{} proxying {} -> {}", SERVER, handler.path(), &proxy.backend);
            };
        }
    }

    router
}
/// Build the Trunk router, this includes that static file server, the WebSocket server,
/// (for autoreload & HMR in the future), as well as any user-defined proxies.
Build the Trunk router, this includes that static file server, the WebSocket server,
(for autoreload & HMR in the future), as well as any user-defined proxies.
Build the Trunk router this includes that static file server the WebSocket server ( for autoreload & HMR in the future ) as well as any user - defined proxies .
fn router(state: Arc<State>, cfg: Arc<RtcServe>) -> Router<BoxRoute> {
    // Build static file server, middleware, error handler & WS route for reloads.
    let mut router = Router::new()
        .nest(&state.public_url, get(serve_dist.layer(TraceLayer::new_for_http())))
        .route(
            "/_trunk/ws",
            get(|ws: WebSocketUpgrade, state: Extension<Arc<State>>| async move {
                ws.on_upgrade(|socket| async move { handle_ws(socket, state.0).await })
            }),
        )
        .layer(AddExtensionLayer::new(state.clone()))
        .boxed();
    tracing::info!("{} serving static assets at -> {}", SERVER, state.public_url.as_str());
    // Build proxies.
    if let Some(backend) = &cfg.proxy_backend {
        if cfg.proxy_ws {
            let handler = ProxyHandlerWebSocket::new(backend.clone(), cfg.proxy_rewrite.clone());
            router = handler.clone().register(router);
            tracing::info!("{} proxying websocket {} -> {}", SERVER, handler.path(), &backend);
        } else {
            let handler = ProxyHandlerHttp::new(state.client.clone(), backend.clone(), cfg.proxy_rewrite.clone());
            router = handler.clone().register(router);
            tracing::info!("{} proxying {} -> {}", SERVER, handler.path(), &backend);
        }
    } else if let Some(proxies) = &cfg.proxies {
        for proxy in proxies.iter() {
            if proxy.ws {
                let handler = ProxyHandlerWebSocket::new(proxy.backend.clone(), proxy.rewrite.clone());
                router = handler.clone().register(router);
                tracing::info!("{} proxying websocket {} -> {}", SERVER, handler.path(), &proxy.backend);
            } else {
                let handler = ProxyHandlerHttp::new(state.client.clone(), proxy.backend.clone(), proxy.rewrite.clone());
                router = handler.clone().register(router);
                tracing::info!("{} proxying {} -> {}", SERVER, handler.path(), &proxy.backend);
            };
        }
    }
    router
}
fn router ( state : Arc < State > , cfg : Arc < RtcServe > ) -> Router < BoxRoute > { // Build static file server, middleware, error handler & WS route for reloads. let mut router = Router :: new ( ) . nest ( & state . public_url , get ( serve_dist . layer ( TraceLayer :: new_for_http ( ) ) ) ) . route ( " " , get ( | ws : WebSocketUpgrade , state : Extension < Arc < State > > | async move { ws . on_upgrade ( | socket | async move { handle_ws ( socket , state . 0 ) . await } ) } ) , ) . layer ( AddExtensionLayer :: new ( state . clone ( ) ) ) . boxed ( ) ; tracing :: info ! ( " " SERVER state public_url as_str ( ) ) ; // Build proxies. if let Some ( backend ) = & cfg . proxy_backend { if cfg . proxy_ws { let handler = ProxyHandlerWebSocket :: new ( backend . clone ( ) , cfg . proxy_rewrite . clone ( ) ) ; router = handler . clone ( ) . register ( router ) ; tracing :: info ! ( " " SERVER handler path ( ) backend ) ; } else { let handler = ProxyHandlerHttp :: new ( state . client . clone ( ) , backend . clone ( ) , cfg . proxy_rewrite . clone ( ) ) ; router = handler . clone ( ) . register ( router ) ; tracing :: info ! ( " " SERVER handler path ( ) backend ) ; } } else if let Some ( proxies ) = & cfg . proxies { for proxy in proxies . iter ( ) { if proxy . ws { let handler = ProxyHandlerWebSocket :: new ( proxy . backend . clone ( ) , proxy . rewrite . clone ( ) ) ; router = handler . clone ( ) . register ( router ) ; tracing :: info ! ( " " SERVER handler path ( ) proxy backend ) ; } else { let handler = ProxyHandlerHttp :: new ( state . client . clone ( ) , proxy . backend . clone ( ) , proxy . rewrite . clone ( ) ) ; router = handler . clone ( ) . register ( router ) ; tracing :: info ! ( " " SERVER handler path ( ) proxy backend ) ; } ; } } router }
Build the Trunk router, this includes that static file server, the WebSocket server,
(for autoreload & HMR in the future), as well as any user-defined proxies.
Build the Trunk router this includes that static file server the WebSocket server ( for autoreload & HMR in the future ) as well as any user - defined proxies .
state
Arc<State>
cfg
Arc<RtcServe>
state
Arc<State>
cfg
Arc<RtcServe>