Get basic path handling to work properly
This commit is contained in:
parent
e5410a7e9e
commit
e9b32173ad
5 changed files with 13 additions and 10 deletions
Before Width: | Height: | Size: 680 KiB After Width: | Height: | Size: 680 KiB |
0
resources/js/example.js
Normal file
0
resources/js/example.js
Normal file
|
@ -3,12 +3,12 @@
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Petersilie Shop</title>
|
<title>Petersilie Shop</title>
|
||||||
<link href="templates/index.css" rel="stylesheet">
|
<link href="/css/index.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="wrapper">
|
<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>
|
<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>
|
<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>
|
<h3 class="title" style='font-size: 10px; color:#0000ff;'>Header info 3</h3>
|
19
src/main.rs
19
src/main.rs
|
@ -1,6 +1,4 @@
|
||||||
use std::path::PathBuf;
|
use actix_files::Files;
|
||||||
|
|
||||||
use actix_files::NamedFile;
|
|
||||||
use actix_web::middleware::Logger;
|
use actix_web::middleware::Logger;
|
||||||
use actix_web::{get, web::Data, App, HttpRequest, HttpResponse, HttpServer, Responder, Result};
|
use actix_web::{get, web::Data, App, HttpRequest, HttpResponse, HttpServer, Responder, Result};
|
||||||
use env_logger::Env;
|
use env_logger::Env;
|
||||||
|
@ -14,7 +12,7 @@ struct AppData {
|
||||||
async fn index(data: Data<AppData>, req: HttpRequest) -> impl Responder {
|
async fn index(data: Data<AppData>, req: HttpRequest) -> impl Responder {
|
||||||
let mut ctx = Context::new();
|
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)
|
HttpResponse::Ok().body(rendered)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,17 +20,22 @@ async fn index(data: Data<AppData>, req: HttpRequest) -> impl Responder {
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
env_logger::init_from_env(
|
env_logger::init_from_env(
|
||||||
Env::default()
|
Env::default()
|
||||||
.default_filter_or("info")
|
// .default_filter_or("info")
|
||||||
.default_filter_or("debug"),
|
.default_filter_or("debug"),
|
||||||
);
|
);
|
||||||
|
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
App::new()
|
App::new()
|
||||||
.service(index)
|
.service(index)
|
||||||
.service(actix_files::Files::new("/resources", ".").show_files_listing())
|
.service(Files::new("/images", "resources/images/").show_files_listing())
|
||||||
.service(actix_files::Files::new("/templates", ".").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 {
|
.app_data(Data::new(AppData {
|
||||||
tmpl: Tera::new("/templates/**/*").unwrap(),
|
tmpl: Tera::new(concat!(
|
||||||
|
env!("CARGO_MANIFEST_DIR"),
|
||||||
|
"/resources/templates/**/*"
|
||||||
|
))
|
||||||
|
.unwrap(),
|
||||||
}))
|
}))
|
||||||
.wrap(Logger::default())
|
.wrap(Logger::default())
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue