feat: update template

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2025-01-11 22:22:39 +01:00
parent 5cf5519524
commit c01c27a0a4
Signed by: kjuulh
SSH Key Fingerprint: SHA256:RjXh0p7U6opxnfd3ga/Y9TCo18FYlHFdSpRIV72S/QM
20 changed files with 247 additions and 2808 deletions

2667
cuddle-leptos/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -9,25 +9,25 @@ lto = true
opt-level = 'z'
[workspace.dependencies]
leptos = { version = "0.6", features = ["nightly"] }
leptos_meta = { version = "0.6", features = ["nightly"] }
leptos_router = { version = "0.6", features = ["nightly"] }
leptos_axum = { version = "0.6" }
server_fn = { version = "0.6", features = [] }
leptos = { version = "0.7.2", features = ["nightly"] }
leptos_meta = { version = "0.7.2" }
leptos_router = { version = "0.7.2", features = ["nightly"] }
leptos_axum = { version = "0.7.2" }
server_fn = { version = "0.7.2", features = [] }
serde = { version = "1", features = ["derive"] }
axum = "0.7"
axum = "0.8"
cfg-if = "1"
console_error_panic_hook = "0.1.7"
console_log = "1"
http = "1"
log = "0.4.21"
simple_logger = "5.0.0"
thiserror = "1"
thiserror = "2"
tokio = { version = "1.37.0", features = ["full"] }
tower = { version = "0.5.0", features = ["full"] }
tower-http = { version = "0.5", features = ["full"] }
wasm-bindgen = "=0.2.93"
tower-http = { version = "0.6", features = ["full"] }
wasm-bindgen = "=0.2.99"
# See https://github.com/akesson/cargo-leptos for documentation of all the parameters.
@ -65,6 +65,9 @@ site-addr = "127.0.0.1:3000"
# The port to use for automatic reload monitoring
reload-port = 3001
# Optional, Activates the tailwind build
tailwind-input-file = "style/tailwind.css"
# [Optional] Command to use when running end2end tests. It will run in the end2end dir.
# [Windows] for non-WSL use "npx.cmd playwright test"
# This binary name can be checked in Powershell with Get-Command npx

View File

@ -16,3 +16,4 @@ tokio.workspace = true
tower.workspace = true
tower-http.workspace = true
log.workspace = true
dotenvy = "0.15.7"

View File

@ -1,44 +0,0 @@
use app::App;
use axum::response::Response as AxumResponse;
use axum::{
body::Body,
extract::State,
http::{Request, Response, StatusCode, Uri},
response::IntoResponse,
};
use leptos::*;
use tower::ServiceExt;
use tower_http::services::ServeDir;
pub async fn file_and_error_handler(
uri: Uri,
State(options): State<LeptosOptions>,
req: Request<Body>,
) -> AxumResponse {
let root = options.site_root.clone();
let res = get_static_file(uri.clone(), &root).await.unwrap();
if res.status() == StatusCode::OK {
res.into_response()
} else {
let handler =
leptos_axum::render_app_to_stream(options.to_owned(), move || view! { <App/> });
handler(req).await.into_response()
}
}
async fn get_static_file(uri: Uri, root: &str) -> Result<Response<Body>, (StatusCode, String)> {
let req = Request::builder()
.uri(uri.clone())
.body(Body::empty())
.unwrap();
// `ServeDir` implements `tower::Service` so we can call it with `tower::ServiceExt::oneshot`
// This path is relative to the cargo root
match ServeDir::new(root).oneshot(req).await {
Ok(res) => Ok(res.map(Body::new)),
Err(err) => Err((
StatusCode::INTERNAL_SERVER_ERROR,
format!("Something went wrong: {err}"),
)),
}
}

View File

@ -1,14 +1,14 @@
use app::*;
use axum::Router;
use fileserv::file_and_error_handler;
use leptos::*;
use leptos::prelude::*;
use leptos_axum::{generate_route_list, LeptosRoutes};
use state::State;
use tokio::signal;
pub mod fileserv;
#[tokio::main]
async fn main() {
let _ = dotenvy::dotenv();
simple_logger::init_with_level(log::Level::Debug).expect("couldn't initialize logging");
// Setting get_configuration(None) means we'll be using cargo-leptos's env values
@ -16,15 +16,31 @@ async fn main() {
// <https://github.com/leptos-rs/start-axum#executing-a-server-on-a-remote-machine-without-the-toolchain>
// Alternately a file can be specified such as Some("Cargo.toml")
// The file would need to be included with the executable when moved to deployment
let conf = get_configuration(None).await.unwrap();
let conf = get_configuration(None).unwrap();
let leptos_options = conf.leptos_options;
let state = State {};
let addr = leptos_options.site_addr;
let routes = generate_route_list(App);
// build our application with a route
let app = Router::new()
.leptos_routes(&leptos_options, routes, App)
.fallback(file_and_error_handler)
.leptos_routes_with_context(
&leptos_options,
routes,
{
let state = state.clone();
move || {
provide_context(state.clone());
}
},
{
let leptos_options = leptos_options.clone();
move || shell(leptos_options.clone())
},
)
.fallback(leptos_axum::file_and_error_handler(shell))
.with_state(leptos_options);
// run our app with hyper

View File

@ -12,14 +12,35 @@ leptos_router.workspace = true
server_fn.workspace = true
leptos_axum = { workspace = true, optional = true }
tokio = {workspace = true, optional = true}
tokio = { workspace = true, optional = true }
serde.workspace = true
http.workspace = true
cfg-if.workspace = true
thiserror.workspace = true
cynic = { version = "3.9.1", optional = true, features = [
"http-reqwest",
"reqwest",
"serde_json",
] }
reqwest = { version = "0.12.11", optional = true, features = ["json"] }
axum = { workspace = true, optional = true, features = ["macros"] }
serde_json = { version = "1.0.134", optional = true }
[features]
default = []
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
ssr = ["leptos/ssr", "leptos_meta/ssr", "leptos_router/ssr", "dep:leptos_axum", "dep:tokio"]
hydrate = ["leptos/hydrate"]
ssr = [
"leptos/ssr",
"leptos_meta/ssr",
"leptos_router/ssr",
"dep:leptos_axum",
"dep:tokio",
"dep:cynic",
"dep:reqwest",
"dep:axum",
"dep:serde_json",
]
cynic = ["dep:cynic"]
reqwest = ["dep:reqwest"]
axum = ["dep:axum"]
serde_json = ["dep:serde_json"]

View File

@ -1,6 +1,6 @@
use cfg_if::cfg_if;
use http::status::StatusCode;
use leptos::*;
use leptos::prelude::*;
use thiserror::Error;
#[cfg(feature = "ssr")]
@ -28,7 +28,7 @@ pub fn ErrorTemplate(
#[prop(optional)] errors: Option<RwSignal<Errors>>,
) -> impl IntoView {
let errors = match outside_errors {
Some(e) => create_rw_signal(e),
Some(e) => RwSignal::new(e),
None => match errors {
Some(e) => e,
None => panic!("No Errors found and we expected errors!"),

View File

@ -1,32 +1,52 @@
use crate::error_template::{AppError, ErrorTemplate};
use leptos::*;
use leptos::prelude::*;
use leptos_meta::*;
use leptos_router::*;
use serde::{Deserialize, Serialize};
use leptos_router::{components::*, StaticSegment};
pub mod error_template;
#[cfg(feature = "ssr")]
pub mod state;
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 />
<MetaTags />
</head>
<body>
<App />
</body>
</html>
}
}
#[component]
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();
view! {
<Stylesheet id="leptos" href="/pkg/%%name%%.css"/>
<Stylesheet id="leptos" href="/pkg/%%name%%.css" />
// sets the document title
<Title text="%%name%%"/>
<Title text="%%name%%" />
// content for this welcome page
<Router fallback=|| {
let mut outside_errors = Errors::default();
outside_errors.insert_with_default_key(AppError::NotFound);
view! { <ErrorTemplate outside_errors/> }.into_view()
}>
<main>
<Routes>
<Route ssr=SsrMode::Async path="" view=HomePage/>
<Router>
<main class="">
<Routes fallback=|| {
let mut outside_errors = Errors::default();
outside_errors.insert_with_default_key(AppError::NotFound);
view! { <ErrorTemplate outside_errors /> }.into_view()
}>
<Route path=StaticSegment("") view=pages::home::HomePage />
</Routes>
</main>
</Router>
@ -34,6 +54,8 @@ pub fn App() -> impl IntoView {
}
#[component]
fn HomePage() -> impl IntoView {
view! {<h1> Hello %%name%% </h1>}
pub fn HomePage() -> impl IntoView {
view! {
<h1> "%%name%%" </h1>
}
}

View File

@ -0,0 +1,14 @@
use axum::extract::FromRef;
use leptos::prelude::expect_context;
use server_fn::ServerFnError;
#[derive(FromRef, Clone)]
pub struct State {}
pub async fn get_state() -> Result<State, ServerFnError> {
let state = expect_context::<crate::state::State>();
let axum::extract::State(state): axum::extract::State<crate::state::State> =
leptos_axum::extract_with_state(&state).await?;
Ok(state)
}

View File

@ -1,12 +1,10 @@
use app::*;
use leptos::*;
use wasm_bindgen::prelude::wasm_bindgen;
#[wasm_bindgen]
#[wasm_bindgen::prelude::wasm_bindgen]
pub fn hydrate() {
use app::*;
// initializes logging using the `log` crate
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
leptos::mount_to_body(App);
leptos::mount::hydrate_body(App);
}

View File

@ -1,10 +0,0 @@
{
"name": "cuddle-leptos",
"templating": "tera",
"delimiter": "[[]]",
"prompt": {
"name": {
"description": "Project name"
}
}
}

View File

@ -6,16 +6,26 @@ vars:
service: "%%name%%"
registry: kasperhermansen
clusters:
clank-prod:
replicas: "3"
namespace: prod
ingress:
- external: "true"
- internal: "true"
cuddle/clusters:
dev:
env:
service.host: "0.0.0.0:3000"
content.url: https://content.front.kjuulh.io/graphql
content.base.url: https://content.front.kjuulh.io
content.token:
vault: true
prod:
env:
service.host: "0.0.0.0:3000"
content.url: https://content.front.kjuulh.io/graphql
content.base.url: https://content.front.kjuulh.io
content.token:
vault: true
deployment:
registry: git@git.front.kjuulh.io:kjuulh/clank-clusters
env:
prod:
clusters:
- clank-prod
scripts:
generate_graphql:
type: shell

View File

@ -13,61 +13,96 @@
}
},
"node_modules/@playwright/test": {
"version": "1.28.0",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.28.0.tgz",
"integrity": "sha512-vrHs5DFTPwYox5SGKq/7TDn/S4q6RA1zArd7uhO6EyP9hj3XgZBBM12ktMbnDQNxh/fL1IUKsTNLxihmsU38lQ==",
"version": "1.49.1",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.49.1.tgz",
"integrity": "sha512-Ky+BVzPz8pL6PQxHqNRW1k3mIyv933LML7HktS8uik0bUXNCdPhoS/kLihiO1tMf/egaJb4IutXd7UywvXEW+g==",
"dev": true,
"dependencies": {
"@types/node": "*",
"playwright-core": "1.28.0"
"playwright": "1.49.1"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=14"
"node": ">=18"
}
},
"node_modules/@types/node": {
"version": "18.11.9",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz",
"integrity": "sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==",
"dev": true
},
"node_modules/playwright-core": {
"version": "1.28.0",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.28.0.tgz",
"integrity": "sha512-nJLknd28kPBiCNTbqpu6Wmkrh63OEqJSFw9xOfL9qxfNwody7h6/L3O2dZoWQ6Oxcm0VOHjWmGiCUGkc0X3VZA==",
"node_modules/fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"dev": true,
"hasInstallScript": true,
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/playwright": {
"version": "1.49.1",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.49.1.tgz",
"integrity": "sha512-VYL8zLoNTBxVOrJBbDuRgDWa3i+mfQgDTrL8Ah9QXZ7ax4Dsj0MSq5bYgytRnDVVe+njoKnfsYkH3HzqVj5UZA==",
"dev": true,
"dependencies": {
"playwright-core": "1.49.1"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=14"
"node": ">=18"
},
"optionalDependencies": {
"fsevents": "2.3.2"
}
},
"node_modules/playwright-core": {
"version": "1.49.1",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.49.1.tgz",
"integrity": "sha512-BzmpVcs4kE2CH15rWfzpjzVGhWERJfmnXmniSyKeRZUs9Ws65m+RGIi7mjJK/euCegfn3i7jvqWeWyHe9y3Vgg==",
"dev": true,
"bin": {
"playwright-core": "cli.js"
},
"engines": {
"node": ">=18"
}
}
},
"dependencies": {
"@playwright/test": {
"version": "1.28.0",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.28.0.tgz",
"integrity": "sha512-vrHs5DFTPwYox5SGKq/7TDn/S4q6RA1zArd7uhO6EyP9hj3XgZBBM12ktMbnDQNxh/fL1IUKsTNLxihmsU38lQ==",
"version": "1.49.1",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.49.1.tgz",
"integrity": "sha512-Ky+BVzPz8pL6PQxHqNRW1k3mIyv933LML7HktS8uik0bUXNCdPhoS/kLihiO1tMf/egaJb4IutXd7UywvXEW+g==",
"dev": true,
"requires": {
"@types/node": "*",
"playwright-core": "1.28.0"
"playwright": "1.49.1"
}
},
"@types/node": {
"version": "18.11.9",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz",
"integrity": "sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==",
"dev": true
"fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"dev": true,
"optional": true
},
"playwright": {
"version": "1.49.1",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.49.1.tgz",
"integrity": "sha512-VYL8zLoNTBxVOrJBbDuRgDWa3i+mfQgDTrL8Ah9QXZ7ax4Dsj0MSq5bYgytRnDVVe+njoKnfsYkH3HzqVj5UZA==",
"dev": true,
"requires": {
"fsevents": "2.3.2",
"playwright-core": "1.49.1"
}
},
"playwright-core": {
"version": "1.28.0",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.28.0.tgz",
"integrity": "sha512-nJLknd28kPBiCNTbqpu6Wmkrh63OEqJSFw9xOfL9qxfNwody7h6/L3O2dZoWQ6Oxcm0VOHjWmGiCUGkc0X3VZA==",
"version": "1.49.1",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.49.1.tgz",
"integrity": "sha512-BzmpVcs4kE2CH15rWfzpjzVGhWERJfmnXmniSyKeRZUs9Ws65m+RGIi7mjJK/euCegfn3i7jvqWeWyHe9y3Vgg==",
"dev": true
}
}

View File

@ -0,0 +1,12 @@
max_width = 100 # Maximum width of each line
tab_spaces = 4 # Number of spaces per tab
indentation_style = "Auto" # "Tabs", "Spaces" or "Auto"
newline_style = "Auto" # "Unix", "Windows" or "Auto"
attr_value_brace_style = "WhenRequired" # "Always", "AlwaysUnlessLit", "WhenRequired" or "Preserve"
macro_names = ["leptos::view", "view"] # Macro names which will be formatted
closing_tag_style = "Preserve" # "Preserve", "SelfClosing" or "NonSelfClosing"
# Attribute values can be formatted by custom formatters
# Every attribute name may only select one formatter (this might change later on)
[attr_values]
class = "Tailwind" # "Tailwind" is the only attribute value formatter available for now

View File

@ -0,0 +1,2 @@
[rustfmt]
overrideCommand = ["leptosfmt", "--stdin", "--rustfmt"]

View File

@ -0,0 +1 @@
edition = "2021"

View File

@ -0,0 +1,5 @@
#!/usr/bin/env zsh
set -e
graphql-schema download --endpoint http://localhost:1337/graphql --output-file crates/app/graphql/content-schema.graphql

View File

@ -6,6 +6,6 @@
body {
font-family: var(--main-font);
background-color: var(--main-background);
color: var(--main-color);
}
//background-color: var(--main-background);
//color: var(--main-color);
}

View File

@ -0,0 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
.page-center {
@apply max-w-4xl mx-auto px-4 h-full;
}

View File

@ -0,0 +1,13 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: {
files: ["*.html", "./crates/app/src/**/*.rs"],
transform: {
rs: (content) => content.replace(/(?:^|\s)class:/g, ' '),
},
},
theme: {
extend: {},
},
plugins: [],
}