Repository: DioxusLabs/dioxus
File: packages/cli/src/server/web/server.rs (Rust)

Code before:
    }

    // Route file service
    router = router.fallback(get_service(file_service).handle_error(
        |error: std::convert::Infallible| async move {
            (
                StatusCode::INTERNAL_SERVER_ERROR,
                format!("Unhandled internal error: {}", error),
            )
        },
    ));

    router = if let Some(base_path) = config.dioxus_config.web.app.base_path.clone() {
        // NB. The trailing `/` is required for Dioxus Routers to match on root paths. Without it,
        // navigating to e.g. `/base/path/` results in the below fallback being hit, and users
        // receiving a message that `/base/path/` is "Outside of the base path: /base/path".
        // Navigating to e.g. `/base/path` results in the below fallback  _not_ being hit, but a
        // panic getting thrown from `WebHistory::route_from_location`. Interestingly, the
        // `RouteParseError` passed into the panic reports that attempts were made to match on no
        // routes at all.
        let base_path = format!("/{}/", base_path.trim_matches('/'));
        Router::new()
            .nest(&base_path, router)
            .fallback(get(move || {
                let base_path = base_path.clone();
                async move { format!("Outside of the base path: {}", base_path) }
            }))
    } else {
        router
    };

    // Setup websocket
    router = router.route("/_dioxus/ws", get(ws_handler));

    // Setup routes
    router = router
        .route("/_dioxus/hot_reload", get(hot_reload_handler))
        .layer(cors)
        .layer(Extension(ws_reload));

    if let Some(hot_reload) = hot_reload {
        router = router.layer(Extension(hot_reload))
    }

    Ok(router)
}

fn no_cache(
    file_service_config: CrateConfig,
    response: Response<ServeFileSystemResponseBody>,
) -> Response<Body> {

Review comment (suggestion):
Calling out this change -- related to the change on :65-66 -- as I'm not 100% sure how this will interact with the proxy configuration on :69-71. I know the order of some methods called on axum routers matter, but I'm not terribly familiar with the framework. I'm also not sure how to correctly test this interaction.

Code after:
    }

    // Route file service
    router = router.fallback(get_service(file_service).handle_error(
        |error: std::convert::Infallible| async move {
            (
                StatusCode::INTERNAL_SERVER_ERROR,
                format!("Unhandled internal error: {}", error),
            )
        },
    ));

    router = if let Some(base_path) = config.dioxus_config.web.app.base_path.clone() {
        let base_path = format!("/{}", base_path.trim_matches('/'));
        Router::new()
            .nest(&base_path, router)
            .fallback(get(move || {
                let base_path = base_path.clone();
                async move { format!("Outside of the base path: {}", base_path) }
            }))
    } else {
        router
    };

    // Setup websocket
    router = router.route("/_dioxus/ws", get(ws_handler));

    // Setup routes
    router = router
        .route("/_dioxus/hot_reload", get(hot_reload_handler))
        .layer(cors)
        .layer(Extension(ws_reload));

    if let Some(hot_reload) = hot_reload {
        router = router.layer(Extension(hot_reload))
    }

    Ok(router)
}

fn no_cache(
    file_service_config: CrateConfig,
    response: Response<ServeFileSystemResponseBody>,
) -> Response<Body> {
    let mut response = if file_service_config.dioxus_config.web.watcher.index_on_404
        && response.status() == StatusCode::NOT_FOUND
    {
        let body = Body::from(
            // TODO: Cache/memoize this.
            std::fs::read_to_string(file_service_config.out_dir().join("index.html"))
                .ok()