Replies: 11 comments
-
I'm confused about what you're trying to accomplish. An actual test case here would have been very useful. In particular, I'm not sure what your desired outcome is: which requests do you want routed where? If you could provide a list of requests and where you'd like them routed, then determining how to declare your routes should be straightforward. Something like this:
|
Beta Was this translation helpful? Give feedback.
-
Sorry for the messy explanation, I've improved my first post adding:
Let me know if you can reproduce the problem or if I'm doing something wrong. |
Beta Was this translation helpful? Give feedback.
-
Neither your test case nor your updated explanation include what you expected to happen. I'm still not sure what you're trying to accomplish. I understand what's happening, but not what you want to make happen. |
Beta Was this translation helpful? Give feedback.
-
I do not want this |
Beta Was this translation helpful? Give feedback.
-
You're still not saying what you do want to happen. |
Beta Was this translation helpful? Give feedback.
-
I guess I need to explain my opinion even if I do not have the knowledge to say that correctly, but ok, let's try, I hope I'm right this time :) I would like to set up I would like to use If even this explanation does not achieve the goal, please help me in writing a sentence that says what one does want to happen, thanks! |
Beta Was this translation helpful? Give feedback.
-
@Luni-4 When you make the request, provide the path to your image file relative to assets folder because that's how you mounted your FileServer |
Beta Was this translation helpful? Give feedback.
-
Yes, you're right about that, but when I remove this line
in order to not have the route
Leaving only the line before, if I'm not wrong, should correspond to Even if I follow this strategy:
I only obtain conflicts |
Beta Was this translation helpful? Give feedback.
-
@Luni-4 If I understood correctly, this is what you are looking for #[launch]
async fn rocket() -> _ {
rocket::build()
.mount("/", routes![index])
.mount("/try", routes![one, second])
.mount("/", FileServer::from(relative!("assets")).rank(5))
.mount("/try", FileServer::from(relative!("assets")).rank(4))
} GET /try text/html:
>> Matched: (second) GET /try/ [2]
>> Outcome: Success(200 OK)
>> Response succeeded.
GET / text/html:
>> Matched: (index) GET /
>> Outcome: Success(200 OK)
>> Response succeeded.
GET /try/img/image.png:
>> Matched: (FileServer: assets) GET /try/<path..> [4]
>> Outcome: Success(200 OK)
>> Remote left: channel closed.
GET /img/image.png:
>> Matched: (FileServer: assets) GET /<path..> [5]
>> Outcome: Success(200 OK)
>> Remote left: channel closed. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for your help, this is what I wanted! In my opinion, it's a bit counterintuitive though, because it's necessary to use ranks which are not present in the web-app. I do not know if it's the same problem, but it happened a similar situation with 2023-12-15T22:31:40.457+01:00 [Runtime] INFO rocket::server: GET /favicon.ico image/avif:
2023-12-15T22:31:40.457+01:00 [Runtime] INFO rocket::server::_: Matched: (FileServer: assets) GET /<path..> [4]
2023-12-15T22:31:40.457+01:00 [Runtime] WARN rocket::response::debug::_: I/O Error: Os { code: 2, kind: NotFound, message: "No such file or directory" }
2023-12-15T22:31:40.457+01:00 [Runtime] INFO rocket::server::_: Outcome: Forward(404 Not Found)
2023-12-15T22:31:40.457+01:00 [Runtime] ERROR rocket::server::_: No matching routes for GET /favicon.ico image/avif.
2023-12-15T22:31:40.457+01:00 [Runtime] WARN rocket::server::_: Responding with registered (not_found) 404 catcher. |
Beta Was this translation helpful? Give feedback.
-
What do you mean by "not present"? Ranks are something you assign to routes to determine which order to try conflicting routes in. The code presented worked ask you wanted because it instructs Rocket to try the
That's a request coming in from the browser. There's nothing wrong with this |
Beta Was this translation helpful? Give feedback.
-
Rocket Version
0.5.0
Operating System
Ubuntu 23.10
Rust Toolchain Version
Rust stable version 1.74.1
What happened?
I do not know if this is an issue, or just me who do not understand how to do things. If it turns out to be the second case, apologies in advance.
When I use
FileServer::rank()
in this example.zip I get theI/O error
present in theLog Output
section when I set the rank.Test Case
Log Output
Additional Context
No response
System Checks
rustc
toolchain.Beta Was this translation helpful? Give feedback.
All reactions