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
35
Cargo.toml
Normal file
35
Cargo.toml
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
[package]
|
||||
name = "pagetop"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
|
||||
authors = [
|
||||
"Manuel Cillero <manuel@cillero.es>"
|
||||
]
|
||||
description = """\
|
||||
PageTop es un proyecto personal para aprender Rust. Incluye algunos de los \
|
||||
crates más estables y populares para desarrollar soluciones web modulares, \
|
||||
extensibles y configurables. También es un sistema para la gestión de \
|
||||
contenidos web.\
|
||||
"""
|
||||
homepage = "https://suitepro.cillero.es/projects/pagetop"
|
||||
repository = "https://gitlab.com/manuelcillero/pagetop"
|
||||
license = "MIT"
|
||||
|
||||
keywords = [
|
||||
"web", "cms", "framework", "frontend", "ssr"
|
||||
]
|
||||
categories = [
|
||||
"web-programming", "development-tools", "gui"
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
actix-web = "4.0.0-rc.3"
|
||||
|
||||
[lib]
|
||||
name = "pagetop"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "pagetop"
|
||||
path = "src/main.rs"
|
||||
14
STARTER.Cargo.toml
Normal file
14
STARTER.Cargo.toml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "app"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# Ver más claves y sus definiciones en
|
||||
# https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
pagetop = { path = "pagetop" }
|
||||
actix-web = "4.0.0-rc.3"
|
||||
|
||||
[[bin]]
|
||||
name = "app"
|
||||
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
|
||||
}
|
||||
9
tests/health_check.rs
Normal file
9
tests/health_check.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fn spawn_app() {
|
||||
let server = pagetop::core::server::run().expect("Failed to bind address");
|
||||
let _ = tokio::spawn(server);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn health_check_works() {
|
||||
spawn_app();
|
||||
}
|
||||
1
tests/main.rs
Normal file
1
tests/main.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
mod health_check;
|
||||
Loading…
Add table
Add a link
Reference in a new issue