use workspaces
This commit is contained in:
parent
697a1fa1f4
commit
998e0ac755
22 changed files with 2786 additions and 143 deletions
1310
Cargo.lock
generated
1310
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
30
Cargo.toml
30
Cargo.toml
|
@ -1,19 +1,13 @@
|
|||
[package]
|
||||
name = "cards"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["Adam Doyle <adam@doordesk.net>"]
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = ["server", "client", "libcards"]
|
||||
default-members = ["server", "libcards"]
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.5"
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
serde_json = "1.0.115"
|
||||
axum = { version = "0.7", features = ["ws"] }
|
||||
futures = "0.3"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tower = { version = "0.4", features = ["util"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
anyhow = "1.0.82"
|
||||
axum-extra = "0.9.3"
|
||||
tower-http = { version = "0.5.2", features = ["fs", "trace"] }
|
||||
[workspace.dependencies]
|
||||
libcards = { path = "./libcards" }
|
||||
|
||||
[profile.release.client]
|
||||
opt-level = 'z'
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
|
|
12
Trunk.toml
Normal file
12
Trunk.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
#
|
||||
# For building the client
|
||||
#
|
||||
|
||||
[build]
|
||||
target = "client/index.html"
|
||||
dist = "dist"
|
||||
release = true
|
||||
minify = "on_release"
|
||||
|
||||
[serve]
|
||||
addresses = ["0.0.0.0"]
|
10
client/Cargo.lock
generated
10
client/Cargo.lock
generated
|
@ -149,6 +149,7 @@ dependencies = [
|
|||
"leptos_meta",
|
||||
"leptos_router",
|
||||
"log",
|
||||
"serde-lite",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-test",
|
||||
"web-sys",
|
||||
|
@ -1217,6 +1218,15 @@ dependencies = [
|
|||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde-lite"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9e8277ab91a9f0d9ba8d626675f18b456372bccbf642db35d36a8f011ae016c"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde-wasm-bindgen"
|
||||
version = "0.6.5"
|
||||
|
|
|
@ -4,12 +4,6 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
authors = ["Adam Doyle <adam@doordesk.net>"]
|
||||
|
||||
[profile.release]
|
||||
opt-level = 'z'
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
@ -20,6 +14,7 @@ console_log = "1"
|
|||
log = "0.4"
|
||||
console_error_panic_hook = "0.1"
|
||||
leptos-use = "0.10.10"
|
||||
serde-lite = "0.5.0"
|
||||
|
||||
# utils
|
||||
# strum = { version = "0.25", features = ["derive", "strum_macros"] }
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
<picture>
|
||||
<source srcset="https://raw.githubusercontent.com/leptos-rs/leptos/main/docs/logos/Leptos_logo_Solid_White.svg" media="(prefers-color-scheme: dark)">
|
||||
<img src="https://raw.githubusercontent.com/leptos-rs/leptos/main/docs/logos/Leptos_logo_RGB.svg" alt="Leptos Logo">
|
||||
</picture>
|
||||
|
||||
# Leptos Client-Side Rendered (CSR) App Starter Template
|
||||
|
||||
This is a template for use with the [Leptos][Leptos] web framework using the [Trunk][Trunk] tool to compile and serve your app in development.
|
||||
|
||||
## Creating your repo from the template
|
||||
|
||||
This template requires you to have `cargo-generate` installed. You can install it with
|
||||
|
||||
```sh
|
||||
cargo install cargo-generate
|
||||
```
|
||||
|
||||
|
||||
To set up your project with this template, run
|
||||
|
||||
```sh
|
||||
cargo generate --git https://github.com/leptos-community/start-csr
|
||||
```
|
||||
|
||||
to generate your new project, then
|
||||
|
||||
```sh
|
||||
cd cards
|
||||
```
|
||||
|
||||
to go to your newly created project.
|
||||
|
||||
By default, this template uses Rust `nightly` and requires that you've installed the `wasm` compilation target for your toolchain.
|
||||
|
||||
|
||||
Sass and Tailwind are also supported by the Trunk build tool, but are optional additions: [see here for more info on how to set those up with Trunk][Trunk-instructions].
|
||||
|
||||
|
||||
If you don't have Rust nightly, you can install it with
|
||||
```sh
|
||||
rustup toolchain install nightly --allow-downgrade
|
||||
```
|
||||
|
||||
You can add the `wasm` compilation target to rust using
|
||||
```sh
|
||||
rustup target add wasm32-unknown-unknown
|
||||
```
|
||||
|
||||
|
||||
## Developing your Leptos CSR project
|
||||
|
||||
To develop your Leptos CSR project, running
|
||||
|
||||
```sh
|
||||
trunk serve --port 3000 --open
|
||||
```
|
||||
|
||||
will open your app in your default browser at `http://localhost:3000`.
|
||||
|
||||
|
||||
## Deploying your Leptos CSR project
|
||||
|
||||
To build a Leptos CSR app for release, use the command
|
||||
|
||||
```sh
|
||||
trunk build --release
|
||||
```
|
||||
|
||||
This will output the files necessary to run your app into the `dist` folder; you can then use any static site host to serve these files.
|
||||
|
||||
For further information about hosting Leptos CSR apps, please refer to [the Leptos Book chapter on deployment available here][deploy-csr].
|
||||
|
||||
|
||||
[Leptos]: https://github.com/leptos-rs/leptos
|
||||
|
||||
[Trunk]: https://github.com/trunk-rs/trunk
|
||||
[Trunk-instructions]: https://trunkrs.dev/assets/
|
||||
|
||||
[deploy-csr]: https://book.leptos.dev/deployment/csr.html
|
|
@ -13,6 +13,7 @@ pub fn Websocket() -> impl IntoView {
|
|||
..
|
||||
} = use_websocket("ws://0.0.0.0:3030/websocket");
|
||||
|
||||
// Websocket stuff
|
||||
let send_message = move |_| {
|
||||
send("Hello, world!");
|
||||
};
|
||||
|
@ -29,6 +30,7 @@ pub fn Websocket() -> impl IntoView {
|
|||
close();
|
||||
};
|
||||
|
||||
// Chat stuff
|
||||
let chat_history_ref = create_node_ref::<Textarea>();
|
||||
|
||||
let (chat_history, set_chat_history) = create_signal(vec![]);
|
||||
|
@ -52,11 +54,14 @@ pub fn Websocket() -> impl IntoView {
|
|||
})
|
||||
});
|
||||
|
||||
// Login stuff
|
||||
let (username, _set_username) = create_signal("ligma");
|
||||
|
||||
view! {
|
||||
<div class="bg-slate-500 w-auto">
|
||||
<div class="w-auto bg-slate-500">
|
||||
<hr/>
|
||||
<h2 class="text-2xl">Connection</h2>
|
||||
<p class="p-1">"status: " {status}</p>
|
||||
<hr/>
|
||||
<div class="p-1">
|
||||
<button on:click=open_connection disabled=connected>
|
||||
"Open"
|
||||
|
@ -67,17 +72,19 @@ pub fn Websocket() -> impl IntoView {
|
|||
</div>
|
||||
<hr/>
|
||||
<div class="p-1">
|
||||
<h2 class="text-2xl">Sign in</h2>
|
||||
<p>Username:</p>
|
||||
<input
|
||||
class="w-96 bg-slate-900 text-slate-200 font-mono rounded-sm"
|
||||
placeholder="who are you?"
|
||||
class="w-96 font-mono rounded-sm bg-slate-900 text-slate-200"
|
||||
placeholder={move || username.get()}
|
||||
/>
|
||||
</div>
|
||||
<hr />
|
||||
<div class="p-1">
|
||||
<p>Chat:</p>
|
||||
<h2 class="text-2xl">Chat</h2>
|
||||
<textarea
|
||||
node_ref=chat_history_ref
|
||||
class="w-96 h-60 bg-slate-900 text-slate-200 font-mono resize-none rounded-sm"
|
||||
class="w-96 h-60 font-mono rounded-sm resize-none bg-slate-900 text-slate-200"
|
||||
readonly=true
|
||||
wrap="soft"
|
||||
>
|
||||
|
@ -85,7 +92,7 @@ pub fn Websocket() -> impl IntoView {
|
|||
</textarea>
|
||||
<br/>
|
||||
<input
|
||||
class="w-96 bg-slate-900 text-slate-200 font-mono rounded-sm"
|
||||
class="w-96 font-mono rounded-sm bg-slate-900 text-slate-200"
|
||||
placeholder="talk shit..."
|
||||
/>
|
||||
<br/>
|
||||
|
|
6
libcards/Cargo.toml
Normal file
6
libcards/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "libcards"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
3
libcards/src/lib.rs
Normal file
3
libcards/src/lib.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub fn test() {
|
||||
println!("ligma!");
|
||||
}
|
23
readme.md
23
readme.md
|
@ -5,17 +5,32 @@ A game master server for the popular game [Cards Against Humanity](https://www.c
|
|||
This started as a problem trying to play games with friends who are all on different platforms. This shall be as cross-platform as it gets. I want it to work on anything that can establish a connection and allow anyone to write any front-end they can dream up whether it be a web page, chat bot, VR, etc. Any clients who share a master server can play together across any platform.
|
||||
|
||||
|
||||
## Dev stuff:
|
||||
## Test/Dev:
|
||||
|
||||
### Server
|
||||
With auto-reload:
|
||||
* [Install cargo-watch](https://watchexec.github.io/#cargo-watch)
|
||||
* `cargo watch -i client -cx run`
|
||||
|
||||
Without auto-reload:
|
||||
* `cargo run`
|
||||
|
||||
### Client
|
||||
* [Install Trunk](https://trunkrs.dev/#install)
|
||||
* `trunk build` or `trunk serve --open` (hot reload on port 8080) from `client` dir to build test client
|
||||
* `trunk serve --open`
|
||||
|
||||
## Build:
|
||||
|
||||
### Client
|
||||
* `trunk build --release`
|
||||
|
||||
### Server
|
||||
* `cargo run` to run server
|
||||
* `cargo build`
|
||||
|
||||
--
|
||||
* The server automatically serves the built client from `/dist` at `0.0.0.0:3030`
|
||||
|
||||
open `localhost:3030` in your browser to run test client or connect to `ws://localhost:3030/websocket` with a custom client
|
||||
* Configure any custom clients to connect to `ws://localhost:3030/websocket`
|
||||
|
||||
|
||||
## TODO:
|
||||
|
|
1396
server/Cargo.lock
generated
Normal file
1396
server/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
21
server/Cargo.toml
Normal file
21
server/Cargo.toml
Normal file
|
@ -0,0 +1,21 @@
|
|||
[package]
|
||||
name = "server"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["Adam Doyle <adam@doordesk.net>"]
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.5"
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
serde_json = "1.0.115"
|
||||
axum = { version = "0.7", features = ["ws"] }
|
||||
futures = "0.3"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tower = { version = "0.4", features = ["util"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
anyhow = "1.0.82"
|
||||
axum-extra = "0.9.3"
|
||||
tower-http = { version = "0.5.2", features = ["fs", "trace"] }
|
||||
|
||||
libcards = { workspace = true }
|
|
@ -110,11 +110,12 @@ async fn css() -> Css<&'static str> {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let _ = libcards::test();
|
||||
// stuff for logging
|
||||
tracing_subscriber::registry()
|
||||
.with(
|
||||
tracing_subscriber::EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| "cards=trace,tower_http=trace".into()),
|
||||
.unwrap_or_else(|_| "server=trace,tower_http=trace".into()),
|
||||
)
|
||||
.with(tracing_subscriber::fmt::layer())
|
||||
.init();
|
||||
|
@ -139,7 +140,7 @@ async fn main() -> Result<()> {
|
|||
.route("/reference_client", get(reference_client))
|
||||
.route("/websocket", get(websocket_handler))
|
||||
.route("/css", get(css))
|
||||
.nest_service("/", ServeDir::new("client/dist"))
|
||||
.nest_service("/", ServeDir::new("dist"))
|
||||
.with_state(app_state);
|
||||
|
||||
// send it
|
|
@ -1,8 +1,12 @@
|
|||
//
|
||||
// This file is here until trunk can be told to source it from /client
|
||||
//
|
||||
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: {
|
||||
relative: true,
|
||||
files: ["*.html", "./src/**/*.rs"],
|
||||
files: ["./client/*.html", "./client/src/**/*.rs"],
|
||||
},
|
||||
theme: {
|
||||
extend: {},
|
Loading…
Add table
Reference in a new issue