-
For the life of me, I can't figure out what's going on here. This seems like it should just work. #[macro_use] extern crate rocket;
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![index])
}
#[get("/?name&<name>")]
fn index(name: Option<&str>) -> String {
if name.is_some() {
format!("Hello, {}!", &name.unwrap())
} else {
"Hello, world!".to_string()
}
} $ ROCKET_PORT=8080 cargo run
>> address: 127.0.0.1
>> port: 8080
>> workers: 32
>> max blocking threads: 512
>> ident: Rocket
>> IP header: X-Real-IP
>> limits: bytes = 8KiB, data-form = 2MiB, file = 1MiB, form = 32KiB, json = 1MiB, msgpack = 1MiB, string = 8KiB
>> temp dir: /tmp
>> http/2: true
>> keep-alive: 5s
>> tls: disabled
>> shutdown: ctrlc = true, force = true, signals = [SIGTERM], grace = 2s, mercy = 3s
>> log level: normal
>> cli colors: true
📬 Routes:
>> (index) GET /?name&<name>
📡 Fairings:
>> Shield (liftoff, response, singleton)
🛡️ Shield:
>> X-Content-Type-Options: nosniff
>> X-Frame-Options: SAMEORIGIN
>> Permissions-Policy: interest-cohort=()
🚀 Rocket has launched from http://127.0.0.1:8080
GET /:
>> No matching routes for GET /.
>> No 404 catcher registered. Using Rocket default.
>> Response succeeded. $ curl localhost:8080
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="color-scheme" content="light dark">
<title>404 Not Found</title>
</head>
<body align="center">
<div role="main" align="center">
<h1>404: Not Found</h1>
<p>The requested resource could not be found.</p>
<hr />
</div>
<div role="contentinfo" align="center">
<small>Rocket</small>
</div>
</body>
</html> $ rustc --version
rustc 1.75.0 (82e1608df 2023-12-21)
$ cargo --version
cargo 1.75.0 (1d8b05cdd 2023-11-20)
$ uname -a
Linux nixos 6.6.40 #1-NixOS SMP PREEMPT_DYNAMIC Mon Jul 15 07:24:53 UTC 2024 x86_64 GNU/Linux Only dependency is |
Beta Was this translation helpful? Give feedback.
Answered by
abhillman
Jul 28, 2024
Replies: 1 comment 1 reply
-
Okay! The confusion I had is with the older docs, which are perhaps ambiguous. I was able to fix this with the following: #[macro_use] extern crate rocket;
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![index])
}
#[get("/?<name>")]
fn index(name: Option<&str>) -> String {
if name.is_some() {
format!("Hello, {}!", &name.unwrap())
} else {
"Hello, world!".to_string()
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
abhillman
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Okay! The confusion I had is with the older docs, which are perhaps ambiguous.
I was able to fix this with the following: