Owows so many new files

This commit is contained in:
2026-09-09 22:20:29 +03:00
parent 3fcee5ea9a
commit 6441cc6709
21 changed files with 3249 additions and 58 deletions

View File

@@ -1,5 +1,21 @@
mod routes;
#[cfg(feature="ssr")]
mod state;
#[cfg(feature="ssr")]
mod server;
#[cfg(feature="ssr")]
pub use server::start;
pub use server::start;
#[cfg(feature="ssr")]
use leptos::config::LeptosOptions;
#[cfg(feature="ssr")]
type Router = axum::Router<LeptosOptions>;
#[cfg(feature = "hydrate")]
#[wasm_bindgen::prelude::wasm_bindgen]
pub fn hydrate() {
use routes::pages::App;
console_error_panic_hook::set_once();
leptos::mount::hydrate_body(App);
}

View File

@@ -0,0 +1,8 @@
mod v1;
pub fn router() -> crate::Router {
crate::Router::new()
.merge(v1::router())
.nest("/v1", v1::router())
}

View File

@@ -0,0 +1,9 @@
use axum::routing::get;
mod health;
pub fn router() -> crate::Router {
crate::Router::new()
.route("/health", get(health::get))
}

View File

@@ -1,8 +1,10 @@
use axum::{routing::get, Router};
pub mod pages;
mod health;
#[cfg(feature="ssr")]
mod api;
pub fn router() -> Router {
Router::new()
.route("/health", get(health::get))
#[cfg(feature="ssr")]
pub fn router() -> crate::Router {
crate::Router::new()
.nest("/api", api::router())
}

View File

@@ -0,0 +1,11 @@
use leptos::prelude::*;
#[component]
pub fn HomePage() -> impl IntoView {
view! {
<main>
<h1>"ERPLT"</h1>
<p>"Welcome to ERPLT."</p>
</main>
}
}

View File

@@ -0,0 +1,32 @@
use leptos::prelude::*;
#[component]
pub fn Layout(children: Children) -> impl IntoView {
view! {
<div class="flex min-h-screen">
<aside class="w-64 border-r p-4">
<h1 class="mb-6 text-xl font-bold">
"ERPLT"
</h1>
<nav class="space-y-2">
<a href="/">"Dashboard"</a>
<a href="/sales">"Sales"</a>
<a href="/purchases">"Purchases"</a>
<a href="/inventory">"Inventory"</a>
<a href="/accounting">"Accounting"</a>
</nav>
</aside>
<div class="flex flex-1 flex-col">
<header class="border-b p-4">
"ERPLT"
</header>
<main class="flex-1 p-6">
{children()}
</main>
</div>
</div>
}
}

View File

@@ -0,0 +1,50 @@
use leptos::prelude::*;
use leptos_meta::*;
use leptos_router::{
SsrMode, StaticSegment, components::{FlatRoutes, Route, Router},
};
mod home;
mod layout;
#[cfg(feature="ssr")]
pub fn shell(options: LeptosOptions) -> impl IntoView {
view! {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<AutoReload options=options.clone() />
<HydrationScripts options/>
<link rel="stylesheet" id="leptos" href="/pkg/erplt.css"/>
<link rel="shortcut icon" type="image/ico" href="/favicon.ico"/>
<MetaTags/>
</head>
<body>
<App/>
</body>
</html>
}
}
#[component]
pub fn App() -> impl IntoView {
provide_meta_context();
view! {
<Router>
<FlatRoutes fallback=|| "Page not found.">
<Route
path=StaticSegment("")
view=|| view! {
<layout::Layout>
<home::HomePage/>
</layout::Layout>
}
ssr=SsrMode::Async
/>
</FlatRoutes>
</Router>
}
}

View File

@@ -1,20 +1,41 @@
use std::{net::{Ipv4Addr, SocketAddr, SocketAddrV4}, str::FromStr};
use anyhow::Context;
use axum::http::StatusCode;
use leptos::prelude::*;
use leptos_axum::{LeptosRoutes, generate_route_list};
use erplt_db::DbPool;
#[axum::debug_handler]
async fn fallback() -> (StatusCode, &'static str) {
(StatusCode::NOT_FOUND, "Not Found")
}
use crate::routes;
pub async fn start(db: DbPool) -> anyhow::Result<()> {
let config = erplt_config::get();
// Need this because tokio has threading panics otherwise
any_spawner::Executor::init_tokio().unwrap();
let leptos_options = LeptosOptions::builder()
.output_name("erplt")
.site_root("target/site")
.site_pkg_dir("pkg")
.reload_external_port(Some((config.web.port+1) as u32))
.site_addr(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::from_str(&config.web.host)?, config.web.port)))
.build();
let routes = generate_route_list(routes::pages::App);
let app = axum::Router::new()
.merge(crate::routes::router())
.fallback(fallback);
//.merge(crate::routes::router())
.merge(routes::router())
.leptos_routes(&leptos_options, routes, {
let leptos_options = leptos_options.clone();
move || routes::pages::shell(leptos_options.clone())
})
.fallback(leptos_axum::file_and_error_handler(routes::pages::shell))
.with_state(leptos_options)
.with_state(db);
@@ -25,7 +46,7 @@ pub async fn start(db: DbPool) -> anyhow::Result<()> {
tracing::info!("Web server listening on http://{}", listener.local_addr()?);
axum::serve(listener, app)
axum::serve(listener, app.into_make_service())
.await
.context("Web server stopped unexpectedly")?;