Compare commits

...

4 Commits

Author SHA1 Message Date
Matthew Gordon 5e90f3436a Add static file serving with favicons
- Serve the "static" directory as static files.
- Add favicons.
2024-02-10 14:17:45 -04:00
Matthew Gordon 856482ce17 Stub in Axum templating 2024-02-10 13:16:37 -04:00
Matthew Gordon 70842b1db2 Create stub Axum app 2024-02-10 12:57:20 -04:00
Matthew Gordon 02af71212e Add Emacs lock and backup files to .gitignore 2024-02-10 12:56:48 -04:00
12 changed files with 86 additions and 0 deletions

2
.cargo/config.toml Normal file
View File

@ -0,0 +1,2 @@
[env]
STATIC_FILE_PATH = { value = "static", relative = true }

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
*.png filter=lfs diff=lfs merge=lfs -text

6
.gitignore vendored
View File

@ -1,3 +1,9 @@
# Emacs
*~
\#*#
.#*
# ---> Rust
# Generated by Cargo
# will have compiled files and executables

13
Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "localhub"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1", features = ["rt-multi-thread"]}
axum = "0.7"
askama = "0.12"
askama_axum = "0.4"
tower-http = { version = "0.5", features = ["fs"] }

25
src/main.rs Normal file
View File

@ -0,0 +1,25 @@
use std::env;
use askama::Template;
use axum::{routing::get, Router};
use tower_http::services::ServeDir;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = Router::new()
.route("/", get(root))
.nest_service("/static", ServeDir::new(env::var("STATIC_FILE_PATH")?));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
axum::serve(listener, app).await?;
Ok(())
}
#[derive(Template)]
#[template(path = "index.html")]
struct IndexTemplate<'a> {
title: &'a str,
}
async fn root<'a>() -> IndexTemplate<'a> {
IndexTemplate { title: "LocalHub" }
}

BIN
static/favicon-16.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
static/favicon-167.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
static/favicon-180.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
static/favicon-192.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
static/favicon-32.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
static/favicon-48.png (Stored with Git LFS) Normal file

Binary file not shown.

21
templates/index.html Normal file
View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>{{title}}</title>
<link rel="icon" type="image/png" sizes="32x32" href="static/favicon-32.png">
<link rel="icon" type="image/png" sizes="16x16" href="static/favicon-16.png">
<!-- For Google and Android -->
<link rel="icon" type="image/png" sizes="48x48" href="static/favicon-48.png">
<link rel="icon" type="image/png" sizes="192x192" href="static/favicon-192.png">
<!-- For iPad -->
<link rel="apple-touch-icon" type="image/png" sizes="167x167" href="static/favicon-167.png">
<!-- For iPhone -->
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="static/favicon-180.png">
</head>
<body>
It still works!
</body>
</html>