Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Spa for serving files for single page apps #234

Closed
wants to merge 1 commit into from
Closed

Conversation

davidpdrsn
Copy link
Member

I'll write a larger description when I've written some tests.

The idea is to use this with axum like so

Router::new()
    .route("/foo", get(|| async { "GET /foo" }))
    .fallback(
        get_service(SpaService::new("./dist"))
            .handle_error(|_| async { StatusCode::INTERNAL_SERVER_ERROR }),
    );

@davidpdrsn
Copy link
Member Author

Hm actually been thinking that we can make can make something nicer in axum, that doesn't require serving assets at the root which is odd I think.

@davidpdrsn davidpdrsn closed this Mar 18, 2022
@jplatte
Copy link
Collaborator

jplatte commented Mar 18, 2022

I kinda liked this idea, but it wasn't clear to me why it would be a separate service rather than a setting on ServeDir where users configure a fallback in case no file is found.

@davidpdrsn
Copy link
Member Author

I was thinking that a helper giving you this setup in axum might be nicer:

Router::new()
    .nest(
        "/assets",
        get_service(ServeDir::new("dist")).handle_error(internal_error),
    )
    .fallback(any_service(ServeFile::new("dist/index.html")).handle_error(internal_error));

@davidpdrsn davidpdrsn deleted the spa branch March 18, 2022 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants