From 8dff02998db9eac1efacf555ccbdec198d7fe213 Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Sat, 15 Mar 2025 13:16:34 +0100 Subject: Self hosted TailwindCSS --- src/bin/web.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/bin/web.rs') diff --git a/src/bin/web.rs b/src/bin/web.rs index eba283c..0384d7f 100644 --- a/src/bin/web.rs +++ b/src/bin/web.rs @@ -3,7 +3,8 @@ use serde::Deserialize; use std::fs; use axum::{ - response::{Html, Json}, + http::header::CONTENT_TYPE, + response::{Html, Json, IntoResponse}, routing::{get, post}, Router, }; @@ -13,7 +14,7 @@ async fn root_get() -> Html { Hiccup - + "; @@ -30,8 +31,12 @@ async fn root_get() -> Html { Html(format!("{head}{body}")) } -async fn main_get() -> Html { - Html(fs::read_to_string("front/main.js").unwrap()) +async fn main_js_get() -> impl IntoResponse { + ([(CONTENT_TYPE, "text/javascript")], fs::read_to_string("front/main.js").unwrap()) +} + +async fn main_css_get() -> impl IntoResponse { + ([(CONTENT_TYPE, "text/css")], fs::read_to_string("front/main.css").unwrap()) } #[derive(Deserialize)] @@ -55,7 +60,8 @@ async fn main() { // build our application with a single route let app = Router::new() .route("/", get(root_get)) - .route("/main.js", get(main_get)) + .route("/main.js", get(main_js_get)) + .route("/main.css", get(main_css_get)) .route("/api/simulate", post(api_simulate_post)); // run our app with hyper, listening globally on port 3000 -- cgit v1.2.3