Skip to content

Commit

Permalink
docs: Add leptos-0.7 example
Browse files Browse the repository at this point in the history
  • Loading branch information
spencewenski committed Oct 20, 2024
1 parent 745f6c3 commit 7a0178b
Show file tree
Hide file tree
Showing 30 changed files with 1,200 additions and 53 deletions.
225 changes: 225 additions & 0 deletions examples/leptos-0.7-ssr/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
# tmp files
*~*

env*/
/target
gen/

# Ignore Cargo.lock because this is a lib crate
Cargo.lock

# Generated by Cargo
# will have compiled files and executables
/target/
pkg

# These are backup files generated by rustfmt
**/*.rs.bk

# node e2e test tools and outputs
node_modules/
test-results/
../end2end/playwright-report/
playwright/.cache/

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
134 changes: 134 additions & 0 deletions examples/leptos-0.7-ssr/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
[package]
name = "leptos-7-ssr-example"
version = "0.1.0"
edition = "2021"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
hydrate = [
"leptos/hydrate",
"dep:wasm-bindgen",
"dep:console_error_panic_hook",
]
ssr = [
"dep:roadster",
"dep:leptos-7-example-entity",
"dep:leptos-7-example-migration",
"dep:axum",
"dep:tokio",
"dep:tokio-util",
"dep:tower",
"dep:tower-http",
"dep:leptos_axum",
"leptos/ssr",
"dep:tracing",
]

[dependencies]
roadster = { version = "0.6", path = "../..", optional = true, default-features = false, features = ["http", "db-sql", "cli"] }
tokio = { workspace = true, optional = true }
tokio-util = { workspace = true, optional = true }
anyhow = { workspace = true }
tracing = { workspace = true, optional = true }
async-trait = { workspace = true }
clap = { workspace = true }

# Http API
axum = { workspace = true, optional = true }

# DB
leptos-7-example-entity = { path = "entity", optional = true }
leptos-7-example-migration = { path = "migration", optional = true }

serde = { workspace = true, features = ["derive"] }

# Leptos
leptos = "0.7.0-gamma3"
console_error_panic_hook = { version = "0.1", optional = true }
leptos_axum = { version = "0.7.0-gamma3", optional = true }
leptos_meta = { version = "0.7.0-gamma3" }
leptos_router = { version = "0.7.0-gamma3" }
leptos_config = { version = "0.7.0-gamma3" }
tower = { workspace = true, features = ["full"], optional = true }
tower-http = { workspace = true, features = ["full"], optional = true }
wasm-bindgen = { version = "=0.2.93", optional = true }

# Defines a size-optimized profile for the WASM bundle in release mode
# Commented out here because profiles are ignored for packages that aren't the workspace root
#[profile.wasm-release]
#inherits = "release"
#opt-level = 'z'
#lto = true
#codegen-units = 1
#panic = "abort"

[package.metadata.leptos]
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "leptos-7-ssr-example"

# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup.
site-root = "target/site"

# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
# Defaults to pkg
site-pkg-dir = "pkg"

# [Optional] The source CSS file. If it ends with .sass or .scss then it will be compiled by dart-sass into CSS. The CSS is optimized by Lightning CSS before being written to <site-root>/<site-pkg>/app.css
style-file = "style/main.scss"
# Assets source dir. All files found here will be copied and synchronized to site-root.
# The assets-dir cannot have a sub directory with the same name/path as site-pkg-dir.
#
# Optional. Env: LEPTOS_ASSETS_DIR.
assets-dir = "public"

# The port to use for automatic reload monitoring
reload-port = 3001

# [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
end2end-cmd = "npx playwright test"
end2end-dir = "end2end"

# The browserlist query used for optimizing the CSS.
browserquery = "defaults"

# The features to use when compiling the bin target
#
# Optional. Can be over-ridden with the command line parameter --bin-features
bin-features = ["ssr"]

# If the --no-default-features flag should be used when compiling the bin target
#
# Optional. Defaults to false.
bin-default-features = false

# The features to use when compiling the lib target
#
# Optional. Can be over-ridden with the command line parameter --lib-features
lib-features = ["hydrate"]

# If the --no-default-features flag should be used when compiling the lib target
#
# Optional. Defaults to false.
lib-default-features = false

# The profile to use for the lib target when compiling for release
#
# Optional. Defaults to "release".
#lib-profile-release = "wasm-release"

[build-dependencies]
vergen = { workspace = true }
vergen-gitcl = { workspace = true }

#[[bin]]
#name = "leptos_ssr_example"
#path = "./src/main.rs"

[lib]
crate-type = ["cdylib", "rlib"]
name = "leptos_7_ssr_example"
path = "./src/lib.rs"
19 changes: 19 additions & 0 deletions examples/leptos-0.7-ssr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Leptos SSR Roadster example

This is an example for how to use [Leptos](https://github.com/leptos-rs/leptos) v0.7 in SSR mode with Roadster.

Feel free to explore the project structure, but the best place to start with your application code is in `src/app.rs`.

## Running your project

```bash
# Start the database and redis (for sidekiq). Note: change the credentials when deploying to prod
docker run -d -p 5432:5432 -e POSTGRES_USER=roadster -e POSTGRES_DB=example_dev -e POSTGRES_PASSWORD=roadster postgres:15.3-alpine
docker run -d -p 6379:6379 redis:7.2-alpine
# From the root Roadster directory, cd into the example dir
cd examples/leptos-ssr
# Run the app
ROADSTER__ENVIRONMENT=development cargo leptos watch -- --config-dir "$(pwd)/config"
# Alternatively, you can put the ROADSTER__ENVIRONMENT=development in a `.env` file and simply run
cargo leptos watch -- --config-dir "$(pwd)/config"
```
9 changes: 9 additions & 0 deletions examples/leptos-0.7-ssr/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use vergen::Emitter;
use vergen_gitcl::GitclBuilder;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let gitcl = GitclBuilder::default().sha(true).build()?;
Emitter::default().add_instructions(&gitcl)?.emit()?;

Ok(())
}
Loading

0 comments on commit 7a0178b

Please sign in to comment.