Añade el servidor web actix-web
This commit is contained in:
parent
6ed78e3934
commit
13a408ce61
9 changed files with 92 additions and 0 deletions
3
src/core/mod.rs
Normal file
3
src/core/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pub use actix_web::dev::Server;
|
||||
|
||||
pub mod server;
|
||||
17
src/core/server/main.rs
Normal file
17
src/core/server/main.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use crate::core::{server, Server};
|
||||
|
||||
async fn greet(req: server::HttpRequest) -> impl server::Responder {
|
||||
let name = req.match_info().get("name").unwrap_or("World");
|
||||
format!("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))
|
||||
})
|
||||
.bind("127.0.0.1:8000")?
|
||||
.run();
|
||||
Ok(server)
|
||||
}
|
||||
4
src/core/server/mod.rs
Normal file
4
src/core/server/mod.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
pub use actix_web::{web, App, HttpRequest, HttpServer, Responder};
|
||||
|
||||
mod main;
|
||||
pub use main::run;
|
||||
3
src/lib.rs
Normal file
3
src/lib.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pub mod core;
|
||||
|
||||
pub use actix_web::main;
|
||||
6
src/main.rs
Normal file
6
src/main.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
use pagetop::core::server;
|
||||
|
||||
#[pagetop::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
server::run()?.await
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue