Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1291c5a33a |
Generated
+1
-1
@@ -1460,7 +1460,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sustenance"
|
name = "sustenance"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "sustenance"
|
name = "sustenance"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
+19
-14
@@ -16,11 +16,7 @@ use axum::{
|
|||||||
use futures_util::{SinkExt, StreamExt};
|
use futures_util::{SinkExt, StreamExt};
|
||||||
use serde::{Deserialize, de::DeserializeOwned};
|
use serde::{Deserialize, de::DeserializeOwned};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tower_http::{
|
use tower_http::trace::{DefaultMakeSpan, DefaultOnResponse, TraceLayer};
|
||||||
services::ServeDir,
|
|
||||||
set_header::SetResponseHeaderLayer,
|
|
||||||
trace::{DefaultMakeSpan, DefaultOnResponse, TraceLayer},
|
|
||||||
};
|
|
||||||
use tracing::{Level, error, warn};
|
use tracing::{Level, error, warn};
|
||||||
|
|
||||||
use crate::domain::{DomainError, SessionUser};
|
use crate::domain::{DomainError, SessionUser};
|
||||||
@@ -29,6 +25,12 @@ use crate::services::{AuthService, InvitationService, ListService, MealService};
|
|||||||
use crate::views;
|
use crate::views;
|
||||||
use crate::webauthn::WebAuthnService;
|
use crate::webauthn::WebAuthnService;
|
||||||
|
|
||||||
|
/// The contents of `static/`, embedded into the binary at compile time so the
|
||||||
|
/// app can be shipped as a single executable without a separate static directory.
|
||||||
|
const STYLE_CSS: &[u8] = include_bytes!("../static/style.css");
|
||||||
|
const PASSKEY_LOGIN_JS: &[u8] = include_bytes!("../static/passkey-login.js");
|
||||||
|
const PASSKEY_REGISTER_JS: &[u8] = include_bytes!("../static/passkey-register.js");
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
pub auth: Arc<AuthService>,
|
pub auth: Arc<AuthService>,
|
||||||
@@ -116,15 +118,7 @@ pub fn build_router(state: AppState) -> Router {
|
|||||||
.route("/lists/{list_id}/stream", get(list_stream))
|
.route("/lists/{list_id}/stream", get(list_stream))
|
||||||
.route("/invite/{token}", get(invitation_page))
|
.route("/invite/{token}", get(invitation_page))
|
||||||
.route("/invite/{token}/accept", post(accept_invitation))
|
.route("/invite/{token}/accept", post(accept_invitation))
|
||||||
.nest_service(
|
.route("/static/{path}", get(static_asset))
|
||||||
"/static",
|
|
||||||
tower::ServiceBuilder::new()
|
|
||||||
.layer(SetResponseHeaderLayer::overriding(
|
|
||||||
header::CACHE_CONTROL,
|
|
||||||
HeaderValue::from_static("public, max-age=0, must-revalidate"),
|
|
||||||
))
|
|
||||||
.service(ServeDir::new("static")),
|
|
||||||
)
|
|
||||||
.layer(
|
.layer(
|
||||||
TraceLayer::new_for_http()
|
TraceLayer::new_for_http()
|
||||||
.make_span_with(DefaultMakeSpan::new().level(Level::INFO))
|
.make_span_with(DefaultMakeSpan::new().level(Level::INFO))
|
||||||
@@ -313,6 +307,17 @@ async fn home() -> Redirect {
|
|||||||
Redirect::to("/lists")
|
Redirect::to("/lists")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Serves a file embedded in the binary from the `static/` folder.
|
||||||
|
async fn static_asset(Path(path): Path<String>) -> Response {
|
||||||
|
let (mime, data) = match path.as_str() {
|
||||||
|
"style.css" => ("text/css", STYLE_CSS),
|
||||||
|
"passkey-login.js" => ("application/javascript", PASSKEY_LOGIN_JS),
|
||||||
|
"passkey-register.js" => ("application/javascript", PASSKEY_REGISTER_JS),
|
||||||
|
_ => return StatusCode::NOT_FOUND.into_response(),
|
||||||
|
};
|
||||||
|
([(header::CONTENT_TYPE, mime)], data).into_response()
|
||||||
|
}
|
||||||
|
|
||||||
async fn log_response_status(request: Request, next: Next) -> Response {
|
async fn log_response_status(request: Request, next: Next) -> Response {
|
||||||
let method = request.method().clone();
|
let method = request.method().clone();
|
||||||
let uri = request.uri().clone();
|
let uri = request.uri().clone();
|
||||||
|
|||||||
Reference in New Issue
Block a user