Get basic path handling to work properly

This commit is contained in:
hodasemi 2023-08-30 17:37:39 +02:00
parent e5410a7e9e
commit e9b32173ad
5 changed files with 13 additions and 10 deletions

View file

Before

Width:  |  Height:  |  Size: 680 KiB

After

Width:  |  Height:  |  Size: 680 KiB

0
resources/js/example.js Normal file
View file

View file

@ -3,12 +3,12 @@
<head>
<title>Petersilie Shop</title>
<link href="templates/index.css" rel="stylesheet">
<link href="/css/index.css" rel="stylesheet">
</head>
<body>
<div id="wrapper">
<img src="resources/petersilie_banner.png">
<img src="/images/petersilie_banner.png">
<h1 class="title" style='font-size: 25px; color:#ffff00;'>Header info 1</h1>
<h2 class="title" style='font-size: 15px; color:#00ff00;'>Header info 2</h2>
<h3 class="title" style='font-size: 10px; color:#0000ff;'>Header info 3</h3>

View file

@ -1,6 +1,4 @@
use std::path::PathBuf;
use actix_files::NamedFile;
use actix_files::Files;
use actix_web::middleware::Logger;
use actix_web::{get, web::Data, App, HttpRequest, HttpResponse, HttpServer, Responder, Result};
use env_logger::Env;
@ -14,7 +12,7 @@ struct AppData {
async fn index(data: Data<AppData>, req: HttpRequest) -> impl Responder {
let mut ctx = Context::new();
let rendered = data.tmpl.render("templates/index.html", &ctx).unwrap();
let rendered = data.tmpl.render("index.html", &ctx).unwrap();
HttpResponse::Ok().body(rendered)
}
@ -22,17 +20,22 @@ async fn index(data: Data<AppData>, req: HttpRequest) -> impl Responder {
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(
Env::default()
.default_filter_or("info")
// .default_filter_or("info")
.default_filter_or("debug"),
);
HttpServer::new(|| {
App::new()
.service(index)
.service(actix_files::Files::new("/resources", ".").show_files_listing())
.service(actix_files::Files::new("/templates", ".").show_files_listing())
.service(Files::new("/images", "resources/images/").show_files_listing())
.service(Files::new("/css", "resources/css").show_files_listing())
.service(Files::new("/js", "resources/js").show_files_listing())
.app_data(Data::new(AppData {
tmpl: Tera::new("/templates/**/*").unwrap(),
tmpl: Tera::new(concat!(
env!("CARGO_MANIFEST_DIR"),
"/resources/templates/**/*"
))
.unwrap(),
}))
.wrap(Logger::default())
})