Añade una arquitectura escalable basada en módulos
This commit is contained in:
parent
e1ea149988
commit
4e23523e80
10 changed files with 108 additions and 19 deletions
|
|
@ -1,22 +1,14 @@
|
|||
use crate::core::{server, Server};
|
||||
use crate::core::{Server, all, server};
|
||||
|
||||
async fn greet() -> impl server::Responder {
|
||||
"Hello!"
|
||||
}
|
||||
pub fn run(bootstrap: Option<fn()>) -> Result<Server, std::io::Error> {
|
||||
// Call application bootstrap.
|
||||
if bootstrap != None {
|
||||
let _ = &(bootstrap.unwrap())();
|
||||
}
|
||||
|
||||
async fn greet_with_param(req: server::HttpRequest) -> server::HttpResponse {
|
||||
let name: String = req.match_info().get("name").unwrap_or("World").into();
|
||||
server::HttpResponse::Ok()
|
||||
.body(sycamore::render_to_string(|ctx| sycamore::view! { ctx,
|
||||
p { "Hello " (name) "!" }
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn run() -> Result<Server, std::io::Error> {
|
||||
let server = server::HttpServer::new(|| {
|
||||
server::App::new()
|
||||
.route("/", server::web::get().to(greet))
|
||||
.route("/{name}", server::web::get().to(greet_with_param))
|
||||
.configure(&all::modules)
|
||||
})
|
||||
.bind("127.0.0.1:8000")?
|
||||
.run();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue