Browse Source
This is mostly coming from another project, which I already set up to this point.master
Julio Biason
4 months ago
commit
3df083eea9
10 changed files with 1155 additions and 0 deletions
@ -0,0 +1,11 @@ |
|||||||
|
[package] |
||||||
|
name = "markvault" |
||||||
|
version = "0.1.0" |
||||||
|
edition = "2021" |
||||||
|
|
||||||
|
[dependencies] |
||||||
|
askama = "0.12.1" |
||||||
|
axum = "0.7.5" |
||||||
|
clap = { version = "4.5.7", features = ["derive", "env"] } |
||||||
|
phf = { version = "0.11.2", features = ["macros"] } |
||||||
|
tokio = { version = "1.38.0", features = ["rt-multi-thread", "macros"] } |
@ -0,0 +1,3 @@ |
|||||||
|
# MarkVault |
||||||
|
|
||||||
|
A Bookmark/Read-It-Later service, for personal use. |
@ -0,0 +1,12 @@ |
|||||||
|
//! Command line arguments
|
||||||
|
|
||||||
|
use std::net::SocketAddr; |
||||||
|
|
||||||
|
use clap::Parser; |
||||||
|
|
||||||
|
#[derive(Parser)] |
||||||
|
pub(super) struct Cli { |
||||||
|
/// Address and port to listen to connections
|
||||||
|
#[arg(default_value = "0.0.0.0:3000")] |
||||||
|
pub address: SocketAddr |
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
//! Index content
|
||||||
|
|
||||||
|
use askama::Template; |
||||||
|
use axum::response::Html; |
||||||
|
|
||||||
|
pub(super) async fn index() -> Html<String> { |
||||||
|
let template = IndexTemplate {}; |
||||||
|
Html(template.render().unwrap()) |
||||||
|
} |
||||||
|
|
||||||
|
#[derive(Template)] |
||||||
|
#[template(path = "index.html")] |
||||||
|
struct IndexTemplate {} |
||||||
|
|
@ -0,0 +1,21 @@ |
|||||||
|
mod args; |
||||||
|
mod index; |
||||||
|
mod staticfiles; |
||||||
|
|
||||||
|
use axum::routing::get; |
||||||
|
use axum::Router; |
||||||
|
use clap::Parser; |
||||||
|
|
||||||
|
#[tokio::main] |
||||||
|
async fn main() { |
||||||
|
// tracing_subscriber::fmt::init();
|
||||||
|
let opts = args::Cli::parse(); |
||||||
|
|
||||||
|
println!("Starting server at {:?}", &opts.address); |
||||||
|
|
||||||
|
let app = Router::new() |
||||||
|
.route("/", get(index::index)) |
||||||
|
.route("/static/:file", get(staticfiles::staticfile)); |
||||||
|
let listener = tokio::net::TcpListener::bind(&opts.address).await.unwrap(); |
||||||
|
axum::serve(listener, app).await.unwrap(); |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
//! Static file serving
|
||||||
|
|
||||||
|
use axum::body::Body; |
||||||
|
use axum::extract::Path; |
||||||
|
use axum::http::header; |
||||||
|
use axum::http::StatusCode; |
||||||
|
use axum::response::Response; |
||||||
|
use phf::phf_map; |
||||||
|
|
||||||
|
static FILES: phf::Map<&'static str, &'static str> = phf_map! { |
||||||
|
"main.css" => include_str!("../../staticfiles/main.css") |
||||||
|
}; |
||||||
|
|
||||||
|
pub(super) async fn staticfile(Path(filename): Path<String>) -> Response { |
||||||
|
match FILES.get(&filename) { |
||||||
|
Some(content) => Response::builder() |
||||||
|
.status(StatusCode::OK) |
||||||
|
.header(header::CONTENT_TYPE, "text/css") |
||||||
|
.body(Body::from(*content)) |
||||||
|
.unwrap(), |
||||||
|
None => Response::builder() |
||||||
|
.status(StatusCode::NOT_FOUND) |
||||||
|
.body(Body::from("Not found")) |
||||||
|
.unwrap(), |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,5 @@ |
|||||||
|
/* main */ |
||||||
|
body { |
||||||
|
background-color: #14142E; |
||||||
|
color: #ffffff; |
||||||
|
} |
Loading…
Reference in new issue