#Serving static files at the root route

1 messages · Page 1 of 1 (latest)

unreal bear
#

Hi, I'm trying out dioxus for the first time, and I'm porting a site from expressjs. I'd like to serve static files alongside the dioxus app, rooted at the root of the site instead of some subroute like /files. So far I have this as my router:

    let router = axum::Router::new()
        .route("/test", get(|| async { "test!" }))
        .nest_service("/", ServeDir::new("/mainzpool/www"))
        .route("/test2", get(|| async { "test2!" }))
        .serve_dioxus_application(ServeConfigBuilder::default(), App)
        .into_make_service();

This works for all the static files and the /test and /test2 routes, but navigating to a dioxus route gives 404 errors.

I've also tried using .fallback_service() instead of .nest_service(). That makes the dioxus routes work, but navigating to a static file's path gives the dioxus-generated 404 page. Test and test2 keep working though.

This might be more of an axum question than dioxus. Is there any way I can get this behavior?

strange jackal
#

I'm no axum expert either, but the ServeDir docs state that the service will return 404, so it seems that the service won't pass on the request handling to dioxus.

#

I just read through the docs. It may be possible to use the .fallback(…) method of ServeDir to change the fallback mechanism of the ServeDir service itself:

.fallback(
    axum::Router::new()
    .serve_dioxus_application(ServeConfigBuilder::default(), App)
    .as_service()
)

But I don't know if that actually works 😅