Updates & axum-controller testing
This commit is contained in:
parent
4fa9f08cc3
commit
80d34a065b
7 changed files with 388 additions and 377 deletions
622
Cargo.lock
generated
622
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -21,7 +21,7 @@ panic = "abort"
|
|||
|
||||
[workspace]
|
||||
members = ["darm_test", "llama_forge_rs", "llama_proxy_man", "redvault_el_rs"]
|
||||
resolver = "2"
|
||||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
authors = ["Tristan Druyen"]
|
||||
|
|
|
@ -11,6 +11,8 @@ edition.workspace = true
|
|||
|
||||
[dependencies]
|
||||
axum = { version = "0.8", features = ["http2"] }
|
||||
axum-controller = { version = "0.2.0", path = "../../axum-controller/axum-controller" }
|
||||
axum-controller-macros = { version = "0.2.0", path = "../../axum-controller/axum-controller-macros" }
|
||||
axum-typed-routing = { git = "https://github.com/jvdwrf/axum-typed-routing", version = "0.2.0" }
|
||||
datastar = { git = "https://github.com/starfederation/datastar.git", version = "0.1.0" }
|
||||
maud = { version = "0.27.0", features = ["axum"] }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
* Planning (newest)
|
||||
- maud vs hypertext vs minijinja
|
||||
- try porting to hypertext ?
|
||||
- try porting to hypertext::maud !
|
||||
* Todos
|
||||
** Starter boilerplate
|
||||
*** [X] Server: Axum
|
||||
|
|
|
@ -7,10 +7,16 @@ use axum::{
|
|||
response::{Html, IntoResponse},
|
||||
routing::get,
|
||||
};
|
||||
use axum_typed_routing::{route, TypedRouter};
|
||||
use axum_controller::*;
|
||||
use maud::{html, Markup};
|
||||
use rust_embed::RustEmbed;
|
||||
|
||||
struct TestController {}
|
||||
|
||||
#[controller(
|
||||
state = AppState
|
||||
)]
|
||||
impl TestController {
|
||||
#[allow(unused)]
|
||||
#[route(GET "/item/:id?amount&offset")]
|
||||
async fn item_handler(
|
||||
|
@ -29,16 +35,19 @@ async fn item_handler(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We use a wildcard matcher ("/dist/*file") to match against everything
|
||||
// within our defined assets directory. This is the directory on our Asset
|
||||
// struct below, where folder = "examples/public/".
|
||||
#[route(GET "/dist/*path")]
|
||||
struct DistController;
|
||||
|
||||
#[controller(state=AppState, path="/dist")]
|
||||
impl DistController {
|
||||
#[route(GET "/*path")]
|
||||
async fn static_handler(path: String, _: State<AppState>) -> impl IntoResponse {
|
||||
let path = path.trim_start_matches('/').to_string();
|
||||
|
||||
StaticFile(path)
|
||||
}
|
||||
}
|
||||
|
||||
fn markup_404(uri: String) -> Markup {
|
||||
html! {
|
||||
|
@ -69,10 +78,6 @@ async fn handle_405() -> impl IntoResponse {
|
|||
(StatusCode::METHOD_NOT_ALLOWED, markup_405()).into_response()
|
||||
}
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "public/"]
|
||||
struct Asset;
|
||||
|
||||
pub struct StaticFile<T>(pub T);
|
||||
|
||||
impl<T> IntoResponse for StaticFile<T>
|
||||
|
@ -82,6 +87,9 @@ where
|
|||
fn into_response(self) -> Response<Body> {
|
||||
let path = self.0.into();
|
||||
tracing::debug!(?path);
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "public/"]
|
||||
struct Asset;
|
||||
|
||||
match Asset::get(path.as_str()) {
|
||||
Some(content) => {
|
||||
|
@ -117,6 +125,10 @@ struct AppState {
|
|||
mj_env: Arc<minijinja::Environment<'static>>,
|
||||
}
|
||||
|
||||
struct JinjaController;
|
||||
|
||||
#[controller(state=AppState)]
|
||||
impl JinjaController {
|
||||
#[route(GET "/")]
|
||||
async fn jinja_index_handler(state: State<AppState>) -> impl IntoResponse {
|
||||
RenderTemplate::new("/".to_string(), state.mj_env.clone())
|
||||
|
@ -126,6 +138,7 @@ async fn jinja_index_handler(state: State<AppState>) -> impl IntoResponse {
|
|||
async fn jinja_index_handler_path(path: String, state: State<AppState>) -> impl IntoResponse {
|
||||
RenderTemplate::new(path, state.mj_env.clone())
|
||||
}
|
||||
}
|
||||
|
||||
struct RenderTemplate {
|
||||
tmpl_name: String,
|
||||
|
@ -276,15 +289,10 @@ async fn main() {
|
|||
// TODO pick free port/config
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:8000").await.unwrap();
|
||||
|
||||
let ui_router = axum::Router::new().typed_route(item_handler);
|
||||
|
||||
let router: axum::Router = axum::Router::new()
|
||||
// .route("/", get(jinja_index_handler))
|
||||
.merge(ui_router.clone())
|
||||
.nest("/ui", ui_router)
|
||||
.typed_route(jinja_index_handler)
|
||||
.typed_route(jinja_index_handler_path)
|
||||
.typed_route(static_handler)
|
||||
.merge(JinjaController::into_router(app_state.clone()))
|
||||
.merge(TestController::into_router(app_state.clone()))
|
||||
.merge(DistController::into_router(app_state.clone()))
|
||||
.fallback_service(get(handle_404))
|
||||
.method_not_allowed_fallback(handle_405)
|
||||
.with_state(app_state);
|
||||
|
|
43
flake.lock
generated
43
flake.lock
generated
|
@ -23,11 +23,11 @@
|
|||
"nixpkgs-lib": "nixpkgs-lib"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1735774679,
|
||||
"narHash": "sha256-soePLBazJk0qQdDVhdbM98vYdssfs3WFedcq+raipRI=",
|
||||
"lastModified": 1741352980,
|
||||
"narHash": "sha256-+u2UunDA4Cl5Fci3m7S643HzKmIDAe+fiXrLqYsR2fs=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "f2f7418ce0ab4a5309a4596161d154cfc877af66",
|
||||
"rev": "f4330d22f1c5d2ba72d3d22df5597d123fdb60a9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -64,16 +64,16 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1739180049,
|
||||
"narHash": "sha256-LjIIeMqGJVv6rHsnf5tWhejiysD3LIsOplwE+M3YeZg=",
|
||||
"lastModified": 1741373670,
|
||||
"narHash": "sha256-BPawysk5uWq9W4K/r+ZJr3AliPemVQqKOuSD7U4Px+Y=",
|
||||
"owner": "ggerganov",
|
||||
"repo": "llama.cpp",
|
||||
"rev": "d7b31a9d84297b493a61c9a8ee3a458e7ccc64a7",
|
||||
"rev": "7ab364390f92b0b8d83f69821a536b424838f3f8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "ggerganov",
|
||||
"ref": "b4681",
|
||||
"ref": "b4855",
|
||||
"repo": "llama.cpp",
|
||||
"type": "github"
|
||||
}
|
||||
|
@ -96,28 +96,31 @@
|
|||
},
|
||||
"nixpkgs-lib": {
|
||||
"locked": {
|
||||
"lastModified": 1735774519,
|
||||
"narHash": "sha256-CewEm1o2eVAnoqb6Ml+Qi9Gg/EfNAxbRx1lANGVyoLI=",
|
||||
"type": "tarball",
|
||||
"url": "https://github.com/NixOS/nixpkgs/archive/e9b51731911566bbf7e4895475a87fe06961de0b.tar.gz"
|
||||
"lastModified": 1740877520,
|
||||
"narHash": "sha256-oiwv/ZK/2FhGxrCkQkB83i7GnWXPPLzoqFHpDD3uYpk=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"rev": "147dee35aab2193b174e4c0868bd80ead5ce755c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
"url": "https://github.com/NixOS/nixpkgs/archive/e9b51731911566bbf7e4895475a87fe06961de0b.tar.gz"
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1738758495,
|
||||
"narHash": "sha256-CZ8T4vP3ag2hwkpSZjatxJb55ouszvmnWw09qxGW9TU=",
|
||||
"lastModified": 1741246872,
|
||||
"narHash": "sha256-Q6pMP4a9ed636qilcYX8XUguvKl/0/LGXhHcRI91p0U=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "ceaea203f3ae1787b1bd13f021f686391696fc5b",
|
||||
"rev": "10069ef4cf863633f57238f179a0297de84bd8d3",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable-small",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
|
@ -170,11 +173,11 @@
|
|||
"nixpkgs": "nixpkgs_3"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1738290352,
|
||||
"narHash": "sha256-YKOHUmc0Clm4tMV8grnxYL4IIwtjTayoq/3nqk0QM7k=",
|
||||
"lastModified": 1741314698,
|
||||
"narHash": "sha256-6Yp0CTwAY/jq/F81Sa8NM0Zi1EwxAdASO6y4A5neGuc=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "b031b584125d33d23a0182f91ddbaf3ab4880236",
|
||||
"rev": "4e9af61c1a631886cdc7e13032af4fc9e75bb76b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
];
|
||||
};
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
|
@ -23,7 +23,7 @@
|
|||
flake = false;
|
||||
};
|
||||
llama-cpp = {
|
||||
url = "github:ggerganov/llama.cpp/b4681";
|
||||
url = "github:ggerganov/llama.cpp/b4855";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs.flake-parts.follows = "flake-parts";
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue