From 7939c9e7b68d5a3ed437d179cfc4d2d7b5cb2eaf Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 13 Feb 2025 23:07:27 +0300 Subject: [PATCH] feat(url): add server-side rendering feature with URL routing --- src/main.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main.rs b/src/main.rs index b2a782a..8246046 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ #[cfg(feature = "ssr")] +use actix_web::{web, HttpResponse}; + #[actix_web::main] async fn main() -> std::io::Result<()> { use actix_files::Files; @@ -55,11 +57,26 @@ async fn main() -> std::io::Result<()> { //.wrap(middleware::Compress::default()) // Pass the database as shared state .app_data(web::Data::new(db)) + // Register URL routing + .service(web::resource("/").route(web::get().to(index))) + .service(web::resource("/{url}").route(web::get().to(url_handler))) }) .bind(&addr)? .run() .await } +#[cfg(feature = "ssr")] +// Define the index handler +async fn index() -> HttpResponse { + HttpResponse::Ok().body("Welcome to CompareWare!") +} +#[cfg(feature = "ssr")] +// Define the URL handler +async fn url_handler(url: web::Path) -> HttpResponse { + let url = url.into_inner(); + // TO DO: Implement URL-based content storage and editing functionality + HttpResponse::Ok().body(format!("You are viewing the content at {}", url)) +} #[cfg(feature = "ssr")] #[actix_web::get("favicon.ico")]