Skip to content

Css files not loading with actix #526

@DogsCodesStudio

Description

@DogsCodesStudio

I have

use actix_files::Files;
use actix_web::{get, web, App, HttpResponse, HttpServer};
use handlebars::Handlebars;
use serde_json::json;

#[get("/")]
async fn tests(hb: web::Data<Handlebars<'_>>) -> HttpResponse {
    let data = json!({
        "user": 25,
        "data": 12
    });
    let body = hb.render("404", &data).unwrap();
    HttpResponse::Ok().body(body)
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let mut handlebars = Handlebars::new();
    handlebars
        .register_templates_directory(".html", "/var/www/templates")
        .unwrap();

    // let tests = Files::new("/static", ".").show_files_listing();
    let handlebars_ref = web::Data::new(handlebars);

    HttpServer::new(move || App::new()
    .service(Files::new("/var/www/templates", ".").show_files_listing())
        .app_data(handlebars_ref.clone())
        .service(tests))
        .bind(("127.0.0.1", 25565))?
        .run()
        .await
}

async fn not_found(hb: web::Data<Handlebars<'_>>) -> HttpResponse {
    let data = json!({
        "user": 25,
        "data": 12
    });
    let body = hb.render("404", &data).unwrap();
    HttpResponse::Ok().body(body)
}``` and 

[dependencies]
actix-web = "4"
actix-files = "0.6.2"
handlebars = { version = "4.2.1", features = ["dir_source"] }
serde = { version = "1.0.143", features = ["derive"] }
serde_json = "1.0.72"

with my template file being 
![image](https://user-images.githubusercontent.com/98062743/186021196-27a77d0b-7a1f-4b29-b918-bdc7306eb397.png)
but it doesn't seem to be loading the css file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions