post route not found #2426
-
I am not sure if I am doing something wrong. I have try to get a post route working. ❯ curl --data 1234 "http://127.0.0.1:8000/register"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<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> rocket log:
my code: use rocket;
use rocket::http::Status;
use crate::CONFIG;
#[post("/register", data = "<token>")]
pub(crate) async fn register(token: String) -> Result<String, Status> {
if token==CONFIG.register_token {
return Ok("TODO".to_owned())
}
Err(Status::Unauthorized)
}
#![warn(rust_2018_idioms)]
#![forbid(unsafe_code)]
#[macro_use]
extern crate rocket;
use rocket::{http::Status, shield::Shield, tokio::task::spawn_blocking};
use rocket_dyn_templates::{context, Template};
...
mod user;
use user::*;
...
#[launch]
async fn rocket() -> _ {
...
rocket::build()
.mount("/", routes![index])
.mount("/register", routes![register])
.attach(Template::fairing())
.attach(shield)
} Full code: https://github.com/LuckyTurtleDev/mstickerpicker/tree/7bb874f35a7036026d8bd4cc27eb88d6af325748 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Using this line |
Beta Was this translation helpful? Give feedback.
Using this line
.mount("/register", routes![register])
the route will be located at "/register/register". I guess you're expecting it to be found at "/register".
So, using
.mount("/", routes![index, register])
should probably work.