From ee4534253b6588d0403ac73087817fce8af9d625 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Sat, 12 Nov 2022 13:43:54 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Reestructura=20API=20para?= =?UTF-8?q?=20instanciar=20la=20aplicaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagetop/src/app.rs | 74 ++++++++++++++++++- pagetop/src/app/application.rs | 72 ------------------ pagetop/src/base.rs | 2 + pagetop/src/{app => base}/banner.rs | 0 pagetop/src/{app => base}/banner/figfont.rs | 0 pagetop/src/{app => base}/banner/slant.flf | 0 pagetop/src/{app => base}/banner/small.flf | 0 pagetop/src/{app => base}/banner/speed.flf | 0 pagetop/src/{app => base}/banner/starwars.flf | 0 pagetop/src/prelude.rs | 3 +- 10 files changed, 75 insertions(+), 76 deletions(-) delete mode 100644 pagetop/src/app/application.rs rename pagetop/src/{app => base}/banner.rs (100%) rename pagetop/src/{app => base}/banner/figfont.rs (100%) rename pagetop/src/{app => base}/banner/slant.flf (100%) rename pagetop/src/{app => base}/banner/small.flf (100%) rename pagetop/src/{app => base}/banner/speed.flf (100%) rename pagetop/src/{app => base}/banner/starwars.flf (100%) diff --git a/pagetop/src/app.rs b/pagetop/src/app.rs index 4d1d98b7..eddda642 100644 --- a/pagetop/src/app.rs +++ b/pagetop/src/app.rs @@ -1,3 +1,73 @@ -mod banner; +use crate::base::banner; +use crate::core::module::ModuleStaticRef; +use crate::core::{module, theme}; +use crate::html::Markup; +use crate::response::FatalError; +use crate::response::page::ResultPage; +use crate::{config, db, locale, server, trace, LazyStatic}; -pub mod application; +use actix_web::dev::Server; + +use std::io::Error; + +pub struct Application { + server: Server, +} + +impl Application { + pub fn prepare(app: ModuleStaticRef) -> Result { + // Rótulo de presentación. + banner::print_on_startup(); + + // Inicia registro de trazas y eventos. + LazyStatic::force(&trace::TRACING); + + // Valida el identificador de idioma. + LazyStatic::force(&locale::LANGID); + + #[cfg(feature = "database")] + // Conecta con la base de datos. + LazyStatic::force(&db::DBCONN); + + // Registra los módulos de la aplicación. + module::all::register_modules(app); + + // Registra los temas de los módulos. + module::all::register_themes(); + + // Registra acciones de los módulos. + module::all::register_actions(); + + // Inicializa los módulos. + module::all::init_modules(); + + #[cfg(feature = "database")] + // Ejecuta actualizaciones pendientes de la base de datos. + module::all::run_migrations(); + + // Prepara el servidor web. + let server = server::HttpServer::new(move || { + server::App::new() + .wrap(tracing_actix_web::TracingLogger::default()) + .configure(module::all::configure_services) + .configure(theme::all::configure_services) + .default_service(server::web::route().to(service_not_found)) + }) + .bind(format!( + "{}:{}", + &config::SETTINGS.server.bind_address, + &config::SETTINGS.server.bind_port + ))? + .run(); + + Ok(Self { server }) + } + + pub fn run(self) -> Result { + Ok(self.server) + } +} + +async fn service_not_found() -> ResultPage { + Err(FatalError::NotFound) +} diff --git a/pagetop/src/app/application.rs b/pagetop/src/app/application.rs deleted file mode 100644 index db219b63..00000000 --- a/pagetop/src/app/application.rs +++ /dev/null @@ -1,72 +0,0 @@ -use crate::core::module::ModuleStaticRef; -use crate::core::{module, theme}; -use crate::html::Markup; -use crate::response::FatalError; -use crate::response::page::ResultPage; -use crate::{config, db, locale, server, trace, LazyStatic}; - -use actix_web::dev::Server; - -use std::io::Error; - -pub struct Application { - server: Server, -} - -impl Application { - pub fn prepare(app: ModuleStaticRef) -> Result { - // Rótulo de presentación. - super::banner::print_on_startup(); - - // Inicia registro de trazas y eventos. - LazyStatic::force(&trace::TRACING); - - // Valida el identificador de idioma. - LazyStatic::force(&locale::LANGID); - - #[cfg(feature = "database")] - // Conecta con la base de datos. - LazyStatic::force(&db::DBCONN); - - // Registra los módulos de la aplicación. - module::all::register_modules(app); - - // Registra los temas de los módulos. - module::all::register_themes(); - - // Registra acciones de los módulos. - module::all::register_actions(); - - // Inicializa los módulos. - module::all::init_modules(); - - #[cfg(feature = "database")] - // Ejecuta actualizaciones pendientes de la base de datos. - module::all::run_migrations(); - - // Prepara el servidor web. - let server = server::HttpServer::new(move || { - server::App::new() - .wrap(tracing_actix_web::TracingLogger::default()) - .configure(module::all::configure_services) - .configure(theme::all::configure_services) - .default_service(server::web::route().to(service_not_found)) - }) - .bind(format!( - "{}:{}", - &config::SETTINGS.server.bind_address, - &config::SETTINGS.server.bind_port - ))? - .run(); - - Ok(Self { server }) - } - - pub fn run(self) -> Result { - Ok(self.server) - } -} - -async fn service_not_found() -> ResultPage { - Err(FatalError::NotFound) -} diff --git a/pagetop/src/base.rs b/pagetop/src/base.rs index d58aa565..4fba6995 100644 --- a/pagetop/src/base.rs +++ b/pagetop/src/base.rs @@ -1,3 +1,5 @@ +pub(crate) mod banner; + pub mod component; pub mod module; pub mod theme; diff --git a/pagetop/src/app/banner.rs b/pagetop/src/base/banner.rs similarity index 100% rename from pagetop/src/app/banner.rs rename to pagetop/src/base/banner.rs diff --git a/pagetop/src/app/banner/figfont.rs b/pagetop/src/base/banner/figfont.rs similarity index 100% rename from pagetop/src/app/banner/figfont.rs rename to pagetop/src/base/banner/figfont.rs diff --git a/pagetop/src/app/banner/slant.flf b/pagetop/src/base/banner/slant.flf similarity index 100% rename from pagetop/src/app/banner/slant.flf rename to pagetop/src/base/banner/slant.flf diff --git a/pagetop/src/app/banner/small.flf b/pagetop/src/base/banner/small.flf similarity index 100% rename from pagetop/src/app/banner/small.flf rename to pagetop/src/base/banner/small.flf diff --git a/pagetop/src/app/banner/speed.flf b/pagetop/src/base/banner/speed.flf similarity index 100% rename from pagetop/src/app/banner/speed.flf rename to pagetop/src/base/banner/speed.flf diff --git a/pagetop/src/app/banner/starwars.flf b/pagetop/src/base/banner/starwars.flf similarity index 100% rename from pagetop/src/app/banner/starwars.flf rename to pagetop/src/base/banner/starwars.flf diff --git a/pagetop/src/prelude.rs b/pagetop/src/prelude.rs index 27aacf34..79be1bab 100644 --- a/pagetop/src/prelude.rs +++ b/pagetop/src/prelude.rs @@ -32,5 +32,4 @@ pub use crate::response::ResponseError; pub use crate::base::component::*; -pub use crate::app; -pub use crate::app::application::Application; +pub use crate::app::Application;