Add static file serving with favicons
- Serve the "static" directory as static files. - Add favicons.
This commit is contained in:
parent
856482ce17
commit
5e90f3436a
|
|
@ -0,0 +1,2 @@
|
||||||
|
[env]
|
||||||
|
STATIC_FILE_PATH = { value = "static", relative = true }
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
*.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
|
@ -10,3 +10,4 @@ tokio = { version = "1", features = ["rt-multi-thread"]}
|
||||||
axum = "0.7"
|
axum = "0.7"
|
||||||
askama = "0.12"
|
askama = "0.12"
|
||||||
askama_axum = "0.4"
|
askama_axum = "0.4"
|
||||||
|
tower-http = { version = "0.5", features = ["fs"] }
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
|
use std::env;
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use axum::{routing::get, Router};
|
use axum::{routing::get, Router};
|
||||||
|
use tower_http::services::ServeDir;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let app = Router::new().route("/", get(root));
|
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?;
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
|
||||||
axum::serve(listener, app).await?;
|
axum::serve(listener, app).await?;
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -4,6 +4,16 @@
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
<title>{{title}}</title>
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
It still works!
|
It still works!
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue