✨ Añade servidor web y primeras macros de PageTop
- Crea el crate raíz `pagetop` y configura el workspace con `helpers/pagetop-macros`. - Añade las macros #[pagetop::main] y #[pagetop::test] que envuelven Actix-web para crear aplicaciones y pruebas asíncronas sin depender explícitamente del framework. - Reexporta, mediante el módulo `service`, los tipos esenciales de Actix-web para gestionar servidores y servicios web. - Implementa `Application::{new, run, test}` para simplificar el arranque y la ejecución de tests. - Expone `pagetop::prelude` con las macros, `service` y `Application` para una API pública coherente. - Incorpora ejemplo `examples/app-basic.rs` que levanta un servidor web vacío con el código mínimo para hacerlo.
This commit is contained in:
parent
45e2882653
commit
cbee4c2cb8
13 changed files with 1818 additions and 1 deletions
50
src/app.rs
Normal file
50
src/app.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
//! Prepara y ejecuta una aplicación creada con `Pagetop`.
|
||||
|
||||
use crate::service;
|
||||
|
||||
use std::io::Error;
|
||||
|
||||
pub struct Application;
|
||||
|
||||
impl Application {
|
||||
/// Crea una instancia de la aplicación.
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
|
||||
/// Ejecuta el servidor web de la aplicación.
|
||||
pub fn run(self) -> Result<service::Server, Error> {
|
||||
// Prepara el servidor web.
|
||||
Ok(service::HttpServer::new(move || Self::service_app())
|
||||
.bind("localhost:8080")?
|
||||
.run())
|
||||
}
|
||||
|
||||
/// Prepara el servidor web de la aplicación para pruebas.
|
||||
pub fn test(
|
||||
self,
|
||||
) -> service::App<
|
||||
impl service::Factory<
|
||||
service::Request,
|
||||
Config = (),
|
||||
Response = service::Response<service::BoxBody>,
|
||||
Error = service::Error,
|
||||
InitError = (),
|
||||
>,
|
||||
> {
|
||||
Self::service_app()
|
||||
}
|
||||
|
||||
// Configura el servicio web de la aplicación.
|
||||
fn service_app() -> service::App<
|
||||
impl service::Factory<
|
||||
service::Request,
|
||||
Config = (),
|
||||
Response = service::Response<service::BoxBody>,
|
||||
Error = service::Error,
|
||||
InitError = (),
|
||||
>,
|
||||
> {
|
||||
service::App::new()
|
||||
}
|
||||
}
|
46
src/lib.rs
Normal file
46
src/lib.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
//! <div align="center">
|
||||
//!
|
||||
//! <img src="https://raw.githubusercontent.com/manuelcillero/pagetop/main/static/banner.png" />
|
||||
//!
|
||||
//! <h1>PageTop</h1>
|
||||
//!
|
||||
//! <p>Un entorno de desarrollo para crear soluciones web modulares, extensibles y configurables.</p>
|
||||
//!
|
||||
//! [](#-license)
|
||||
//!
|
||||
//! <br>
|
||||
//! </div>
|
||||
//!
|
||||
//! `PageTop` reivindica la esencia de la web clásica usando [Rust](https://www.rust-lang.org/es)
|
||||
//! para la creación de soluciones web SSR (*renderizadas en el servidor*) basadas en HTML, CSS y
|
||||
//! JavaScript.
|
||||
//!
|
||||
//! # ⚡️ Guía rápida
|
||||
//!
|
||||
//! La aplicación más sencilla de `PageTop` se ve así:
|
||||
//!
|
||||
//! ```rust#ignore
|
||||
//! use pagetop::prelude::*;
|
||||
//!
|
||||
//! #[pagetop::main]
|
||||
//! async fn main() -> std::io::Result<()> {
|
||||
//! Application::new().run()?.await
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
|
||||
// RE-EXPORTED *************************************************************************************
|
||||
|
||||
pub use pagetop_macros::{main, test};
|
||||
|
||||
// API *********************************************************************************************
|
||||
|
||||
// Gestión del servidor y servicios web.
|
||||
pub mod service;
|
||||
// Prepara y ejecuta la aplicación.
|
||||
pub mod app;
|
||||
|
||||
// PRELUDE *****************************************************************************************
|
||||
|
||||
pub mod prelude;
|
11
src/prelude.rs
Normal file
11
src/prelude.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
//! *Prelude* de `PageTop`.
|
||||
|
||||
// RE-EXPORTED.
|
||||
|
||||
pub use crate::{main, test};
|
||||
|
||||
// API.
|
||||
|
||||
pub use crate::service;
|
||||
|
||||
pub use crate::app::Application;
|
9
src/service.rs
Normal file
9
src/service.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
//! Gestión del servidor y servicios web ([actix-web](https://docs.rs/actix-web)).
|
||||
|
||||
pub use actix_web::body::BoxBody;
|
||||
pub use actix_web::dev::Server;
|
||||
pub use actix_web::dev::ServiceFactory as Factory;
|
||||
pub use actix_web::dev::ServiceRequest as Request;
|
||||
pub use actix_web::dev::ServiceResponse as Response;
|
||||
pub use actix_web::{http, rt, test};
|
||||
pub use actix_web::{App, Error, HttpServer};
|
Loading…
Add table
Add a link
Reference in a new issue