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

axum-extra SpaRouter support include_dir! #1698

Closed
1 task done
Sherlock-Holo opened this issue Jan 14, 2023 · 2 comments
Closed
1 task done

axum-extra SpaRouter support include_dir! #1698

Sherlock-Holo opened this issue Jan 14, 2023 · 2 comments

Comments

@Sherlock-Holo
Copy link

  • I have looked for existing issues (including closed) about this

Feature Request

Motivation

when using SpaRouter, it needs a real dir in the fs, however, sometimes the resources may include in the binary by something like include_dir!.

If SpaRouter allows using a virtual dir to access the resources, it will increase the practical

Proposal

maybe SpaRouter can provide a trait like

trait VirtualDir {
    type VirtualFile: AsyncRead + AsyncWrite + AsyncSeek + Unpin + Send + 'static;
    type VirtualFilenameStream: Stream<Item=io::Result<PathBuf>> + Unpin + Send + 'static;


    async fn open_file(&self, name: &str) -> io::Result<Self::VirtualFile>;

    async fn list_files(&self, dir: &str) -> io::Result<Self::VirtualFilenameStream>;
}

to allow user pass a virtual dir to the SpaRouter

Alternatives

user can also try to write the file data to a tmp dir and let SpaRouter access them, but I don't think this way is a good idea

@davidpdrsn
Copy link
Member

This is something we're already working on in tower-http. See tower-rs/tower-http#309 and tower-rs/tower-http#313.

How exactly that'll be integrated into SpaRouter is unclear but until its landed in tower-http there isn't much we can do.

I'm actually considering removing SpaRouter all together since ServeDir is soon gonna be easier to use (thanks to tower-rs/tower-http#283). It is also more flexible (see https://github.com/tokio-rs/axum/blob/main/examples/static-file-server/src/main.rs). But thats a separate discussion of course. Though I think I'll close this issue for now. Feel free to ask follow up questions though :)

@davidpdrsn davidpdrsn closed this as not planned Won't fix, can't repro, duplicate, stale Jan 14, 2023
@gko
Copy link

gko commented Apr 14, 2024

made a small POC with include_dir https://dev.to/konstantin/bundle-frontend-with-axum-build-using-includedir-g8i

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

No branches or pull requests

3 participants