-
Notifications
You must be signed in to change notification settings - Fork 83
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
actix example doesn't load files #24
Comments
Sorry. The actix example is TBD at the moment for a very long time. Will finish it when I get the time and based on need. |
I'm very interested in the actix example because I want to do the same for my rust application for which I'm creating a GUI with yew.. Would this crate be necessary? https://crates.io/crates/mime_guess |
Maybe. In the rocket example I use rockets inbuilt content guesser. let content_type = ContentType::from_extension(ext).expect("Could not get file content type"); Maybe actix has an example like this. |
Thanks to @Gowee We have a working example now. Or do we need some more improvements for this to be closed. |
@Boscop Yes. The crate mime_guess is needed to response |
@Gowee Thanks. But in the actix example I don't see where it use the file extension of the path. It only does I currently have: .resource("/{tail:.*}", move |r| r.f({
move |r| -> Result<fs::NamedFile> {
let mut path: String = r.match_info().query("tail")?;
if path == "" {
path = "index.html".into();
}
match Asset::get(path) {
Some(content) => HttpResponse::Ok().body(content),
None => HttpResponse::NotFound().body("404 Not Found"),
}
}
})) How can I use the mime type I get from mime_guess to set the content type of the |
@Boscop HttpResponse::Ok()
.content_type(guess_mime_type(path).as_ref())
.body(content) should work. |
.resource("/{tail:.*}", move |r| r.f({
move |r| {
let mut path: String = r.match_info().query("tail").unwrap();
if path == "" {
path = "index.html".into();
}
match Assets::get(&path) {
Some(content) => HttpResponse::Ok().content_type(&mime_guess::guess_mime_type(path)).body(content),
None => HttpResponse::NotFound().body("404 Not Found"),
}
}
}))
So how can I do this? (Without going through a |
|
Ah thanks, I was using #[derive(RustEmbed)]
#[folder = "../target/deploy"] // built with yew: cargo web deploy. the `..` is because this crate is part of a workspace
struct Assets; .resource("/{tail:.*}", move |r| r.f({
move |r| {
let mut path: String = r.match_info().query("tail").unwrap();
if path == "" {
path = "index.html".into();
}
println!("{}", path);
match Assets::get(&path) {
Some(content) => HttpResponse::Ok().content_type(mime_guess::guess_mime_type(path).as_ref()).body(content),
None => HttpResponse::NotFound().body("404 Not Found"),
}
}
})) E.g. I try with |
@Boscop |
Thanks, I also had to add another level of But it STILL doesn't work, still 404 error.. |
|
Haha.. This is where the Welcome to suggestions and PR's for this |
@pyros2097 I'm only using The problem is: In debug build, the dir would have to be Since the build (and its embedded files) should not depend on the dir from where That way, the same path (relative to the .rs file's folder, or absolute) can be used for both debug and release builds. After all, that is the goal of this crate, right? :) Otherwise people would be limited to absolute paths, which would be horrible for teams (everyone has their own different folder structure). |
Ah no, when I use |
Haha... It works because it finds the files in your debug folder which is still present because its not cleaned. |
@pyros2097 But there are other crates that embed the files regardless of build mode! (At least 4 other crates, really.) Btw, what do you mean by "It works because it finds the files in your debug folder which is still present because its not cleaned."? ( |
@Boscop Got it. This kind of use case didn't cross my mind. Will keep it the same way. Also will look for a proper solution for dev/prod paths being resolved properly. For the time being it works within the project root folder |
The actix example doesn't load any of the files from
Asset
, it only shows "Hello World" :)The text was updated successfully, but these errors were encountered: