Created workspace for seperate fe/be dev, updated README and Dockerfile.
This commit is contained in:
parent
b5de97e2aa
commit
c029cd0d08
21
Cargo.toml
21
Cargo.toml
@ -4,21 +4,14 @@ version = "0.1.0"
|
|||||||
authors = ["Ada Werefox <ada.werefox@tutanota.com>"]
|
authors = ["Ada Werefox <ada.werefox@tutanota.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"rust-letter-fe",
|
||||||
|
"rust-letter-be",
|
||||||
|
]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dioxus = "0.3.2"
|
rust-letter-be = { path = "./rust-letter-be" }
|
||||||
dioxus-ssr = "0.3.0"
|
|
||||||
rocket = "=0.5.0-rc.3"
|
rocket = "=0.5.0-rc.3"
|
||||||
log = "0.4.6"
|
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
|
||||||
dioxus-web = "0.3.1"
|
|
||||||
# WebAssembly Debug
|
|
||||||
wasm-logger = "0.2.0"
|
|
||||||
console_error_panic_hook = "0.1.7"
|
|
||||||
wasm-bindgen = "0.2"
|
|
||||||
|
|
||||||
[dependencies.rocket_dyn_templates]
|
|
||||||
version = "=0.1.0-rc.3"
|
|
||||||
features = ["handlebars"]
|
|
||||||
|
17
Dockerfile
17
Dockerfile
@ -4,12 +4,23 @@ WORKDIR /usr/src/app
|
|||||||
|
|
||||||
RUN apk add git musl-dev
|
RUN apk add git musl-dev
|
||||||
|
|
||||||
COPY Cargo.toml .
|
COPY data/ data/
|
||||||
COPY public/ public/
|
COPY public/ public/
|
||||||
COPY Rocket.toml .
|
COPY rust-letter-be/ rust-letter-be/
|
||||||
|
|
||||||
|
# We don't need all the front end directory files
|
||||||
|
RUN mkdir rust-letter-fe
|
||||||
|
COPY rust-letter-fe/src/ rust-letter-fe/src/
|
||||||
|
COPY rust-letter-fe/Cargo.toml rust-letter-fe/Cargo.toml
|
||||||
|
|
||||||
COPY src/ src/
|
COPY src/ src/
|
||||||
COPY templates/ templates/
|
COPY templates/ templates/
|
||||||
|
COPY Cargo.toml .
|
||||||
|
COPY Rocket.toml .
|
||||||
|
|
||||||
RUN cargo install --config "net.git-fetch-with-cli=true" --path .
|
RUN cargo install --config "net.git-fetch-with-cli=true" --path .
|
||||||
|
|
||||||
CMD ["rust-letter"]
|
ENV RUST_ADDRESS=0.0.0.0
|
||||||
|
ENV RUST_PORT=3469
|
||||||
|
|
||||||
|
CMD ["cargo", "run", "--release"]
|
||||||
|
85
README.md
85
README.md
@ -4,41 +4,77 @@
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Just build
|
> This project works by using a Cargo workspace with two projects `rust-letter-fe` and `rust-letter-be`
|
||||||
|
|
||||||
```
|
### Backend
|
||||||
cargo build
|
|
||||||
```
|
|
||||||
|
|
||||||
### Start a `dev-server` for the project:
|
You can develop the backend by simply running the project from the root directory
|
||||||
|
|
||||||
```
|
```
|
||||||
cargo run
|
cargo run
|
||||||
```
|
```
|
||||||
|
|
||||||
### Package this project:
|
Generally, any commands you'd use for any other standard Rust project will work for this.
|
||||||
|
|
||||||
|
|
||||||
|
Ex:
|
||||||
```
|
```
|
||||||
cargo build --release
|
cargo build
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ignore This Section
|
### Frontend
|
||||||
|
|
||||||
> **TODO:** Make subcrates for Dioxus and Rocket, should enable dev server for Dioxus while maintaining overall compatibility.
|
If you want to develop the Dioxus frontend, you'll need to do the following:
|
||||||
|
|
||||||
(or, I personally use the following since port `8080` is usually being used and I want hot reloading)
|
- [From the official Dioxus docs](https://dioxuslabs.com/docs/0.3/guide/en/getting_started/web), ensure you have `dioxus-cli` and the `wasm32-unknown-unknown` target installed
|
||||||
|
|
||||||
```
|
```
|
||||||
dioxus serve --hot-reload --port 8234
|
cargo install dioxus-cli
|
||||||
|
```
|
||||||
|
```
|
||||||
|
rustup target add wasm32-unknown-unknown
|
||||||
|
```
|
||||||
|
- Additionally, you *may* need to have the [Tauri prerequisites](https://tauri.app/v1/guides/getting-started/prerequisites/) installed.
|
||||||
|
|
||||||
|
Then, you should be able to run the development server after moving into the `rust-letter-fe` directory.
|
||||||
|
|
||||||
|
(Linux example)
|
||||||
|
```
|
||||||
|
cd rust-letter-fe && dioxus serve
|
||||||
```
|
```
|
||||||
|
|
||||||
## Docker
|
If you'd link to know about how to use `dioxus-cli`, you should run `dioxus --help` or [reference the official documentation.*](https://github.com/DioxusLabs/cli)
|
||||||
|
|
||||||
|
\* At the time of writing this, the link to the documentation is broken. If you'd like to see what I normally use to run the project, here's an example: `dioxus serve --hot-reload --port [port #]`
|
||||||
|
|
||||||
|
## Running
|
||||||
|
|
||||||
|
> Here are some ways you can run the project
|
||||||
|
|
||||||
|
### Cargo
|
||||||
|
|
||||||
|
You can either do the standard `run --release`
|
||||||
|
|
||||||
|
```
|
||||||
|
cargo run --release
|
||||||
|
```
|
||||||
|
|
||||||
|
Or, referencing the Dockerfile, you can install and then run.
|
||||||
|
|
||||||
|
```
|
||||||
|
cargo install --path .
|
||||||
|
```
|
||||||
|
```
|
||||||
|
rust-letter
|
||||||
|
```
|
||||||
|
|
||||||
|
### Docker
|
||||||
|
|
||||||
You can run this in a container using the included `Dockerfile`.
|
You can run this in a container using the included `Dockerfile`.
|
||||||
|
|
||||||
```
|
```
|
||||||
docker build -t letter-werefox-cafe .
|
docker build -t rust-letter-werefox-cafe
|
||||||
docker run -p 3469 -d -t letter-werefox-cafe
|
docker run -p 3469 -d -t rust-letter-werefox-cafe
|
||||||
```
|
```
|
||||||
|
|
||||||
Or, run through docker compose.
|
Or, run through docker compose.
|
||||||
@ -50,11 +86,18 @@ docker compose up --build -d
|
|||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
.project
|
.dioxus-letter-werefox-cafe
|
||||||
- public # save the assets you want include in your project.
|
|- data # text files that will be read to for data in the app
|
||||||
- src # put your code
|
|- public # save the assets you want include in your project.
|
||||||
- - utils # save some public function
|
|- rust-letter-be
|
||||||
- - data # text files that will be read to for data in the app
|
|\
|
||||||
- - components # save some custom components
|
||- src # source code folder for backend
|
||||||
- - templates # put template files here, right now just using handlebar
|
|- rust-letter-fe
|
||||||
|
|\
|
||||||
|
||- src # source code folder for frontend
|
||||||
|
||\
|
||||||
|
|||- utils # save some public function
|
||||||
|
|||- components # save some custom components
|
||||||
|
|- src # code for running the workspace
|
||||||
|
|- templates # put template files here, right now just using handlebar
|
||||||
```
|
```
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[default]
|
[default]
|
||||||
address = "0.0.0.0"
|
port = 3469
|
||||||
# workers = 16
|
# workers = 16
|
||||||
# max_blocking = 512
|
# max_blocking = 512
|
||||||
# keep_alive = 5
|
# keep_alive = 5
|
||||||
@ -13,7 +13,7 @@ ident = "rust-letter-werefox-cafe"
|
|||||||
port = 8234
|
port = 8234
|
||||||
|
|
||||||
[release]
|
[release]
|
||||||
port = 3469
|
address = "0.0.0.0"
|
||||||
secret_key = "yqXUwxWOGD6X7yZaMbRnOXsNjiDMicveyC2imK48KbM="
|
secret_key = "yqXUwxWOGD6X7yZaMbRnOXsNjiDMicveyC2imK48KbM="
|
||||||
|
|
||||||
# [default.limits]
|
# [default.limits]
|
||||||
|
2
public/styles/tailwind.min.css
vendored
2
public/styles/tailwind.min.css
vendored
File diff suppressed because one or more lines are too long
20
rust-letter-be/Cargo.toml
Normal file
20
rust-letter-be/Cargo.toml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
[package]
|
||||||
|
name = "rust-letter-be"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Ada Werefox <ada.werefox@tutanota.com>"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rust-letter-fe = { path = "../rust-letter-fe" }
|
||||||
|
dioxus-ssr = "0.3.0"
|
||||||
|
log = "0.4.6"
|
||||||
|
|
||||||
|
# If you're unsure about why we're depending on a release candidate,
|
||||||
|
# check the Rocket documentation:
|
||||||
|
# https://rocket.rs/v0.5-rc/guide/upgrading/
|
||||||
|
rocket = "=0.5.0-rc.3"
|
||||||
|
|
||||||
|
# Needed to enable handlebar template support
|
||||||
|
[dependencies.rocket_dyn_templates]
|
||||||
|
version = "=0.1.0-rc.3"
|
||||||
|
features = ["handlebars"]
|
34
rust-letter-be/src/lib.rs
Normal file
34
rust-letter-be/src/lib.rs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
pub mod web_app_backend {
|
||||||
|
|
||||||
|
use rocket::fs::FileServer;
|
||||||
|
use rocket::{Rocket, Build};
|
||||||
|
use rocket_dyn_templates::{Template, context};
|
||||||
|
use rust_letter_fe::web_app::{self, VirtualDom};
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
async fn index() -> Template {
|
||||||
|
let mut vdom = VirtualDom::new(web_app::App);
|
||||||
|
let _ = vdom.rebuild();
|
||||||
|
let output = dioxus_ssr::render(&vdom);
|
||||||
|
Template::render(
|
||||||
|
"index",
|
||||||
|
context! {
|
||||||
|
app_title: "A Letter For You!",
|
||||||
|
style_include: "<link href=/styles/tailwind.min.css rel=stylesheet />",
|
||||||
|
test: &output
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn build_rocket() -> Rocket<Build> {
|
||||||
|
rocket::build()
|
||||||
|
.mount("/images", FileServer::from("public/images"))
|
||||||
|
.mount("/styles", FileServer::from("public/styles"))
|
||||||
|
.mount("/fonts", FileServer::from("public/fonts"))
|
||||||
|
.mount("/", routes![index]).attach(Template::fairing())
|
||||||
|
}
|
||||||
|
}
|
16
rust-letter-fe/Cargo.toml
Normal file
16
rust-letter-fe/Cargo.toml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[package]
|
||||||
|
name = "rust-letter-fe"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Ada Werefox <ada.werefox@tutanota.com>"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
dioxus = "0.3.2"
|
||||||
|
|
||||||
|
# Only need these when we're using this crate as a dev server
|
||||||
|
[target.'cfg(target_family = "wasm")'.dependencies]
|
||||||
|
dioxus-web = "0.3.1"
|
||||||
|
dioxus-autofmt = "0.3.0"
|
||||||
|
# WebAssembly Debug
|
||||||
|
wasm-logger = "0.2.0"
|
||||||
|
console_error_panic_hook = "0.1.7"
|
@ -11,7 +11,7 @@ default_platform = "web"
|
|||||||
out_dir = "dist"
|
out_dir = "dist"
|
||||||
|
|
||||||
# resource (public) file folder
|
# resource (public) file folder
|
||||||
asset_dir = "public"
|
asset_dir = "../public"
|
||||||
|
|
||||||
[web.app]
|
[web.app]
|
||||||
|
|
||||||
@ -24,13 +24,13 @@ title = "A Letter For You!"
|
|||||||
reload_html = true
|
reload_html = true
|
||||||
|
|
||||||
# which files or dirs will be watcher monitoring
|
# which files or dirs will be watcher monitoring
|
||||||
watch_path = ["src", "public", "tailwind.config.js", "Dioxus.toml", "Cargo.toml", "build.rs"]
|
watch_path = ["src", "../data", "../public", "tailwind.config.js", "Dioxus.toml", "Cargo.toml", "build.rs"]
|
||||||
|
|
||||||
# include `assets` in web platform
|
# include `assets` in web platform
|
||||||
[web.resource]
|
[web.resource]
|
||||||
|
|
||||||
# CSS style file
|
# CSS style file
|
||||||
style = ["tailwind.min.css"]
|
style = ["styles/tailwind.min.css"]
|
||||||
|
|
||||||
# Javascript code file
|
# Javascript code file
|
||||||
script = []
|
script = []
|
@ -1,7 +1,7 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let mut tailwind = std::process::Command::new("npx");
|
let mut tailwind = std::process::Command::new("npx");
|
||||||
tailwind.args(
|
tailwind.args(
|
||||||
"tailwindcss -i src/index.css -c tailwind.config.js -o public/styles/tailwind.min.css --minify"
|
"tailwindcss -i src/index.css -c tailwind.config.js -o ../public/styles/tailwind.min.css --minify"
|
||||||
.split(" "),
|
.split(" "),
|
||||||
);
|
);
|
||||||
tailwind.env("NODE_ENV", "production");
|
tailwind.env("NODE_ENV", "production");
|
@ -1,7 +1,8 @@
|
|||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
pub mod web_app {
|
pub mod web_app {
|
||||||
// import the prelude to get access to the `rsx!` macro and the `Scope` and `Element` types
|
// import the prelude to get access to the `rsx!` macro and the `Scope` and `Element` types
|
||||||
use dioxus::prelude::*;
|
pub use dioxus::prelude::*;
|
||||||
|
|
||||||
pub fn App(cx: Scope) -> Element {
|
pub fn App(cx: Scope) -> Element {
|
||||||
cx.render(rsx!(
|
cx.render(rsx!(
|
||||||
@ -36,7 +37,7 @@ pub mod web_app {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn MakePoem(cx: Scope) -> Element {
|
fn MakePoem(cx: Scope) -> Element {
|
||||||
let poem = include_str!("data/poem.txt").split("\n\n");
|
let poem = include_str!("../../data/poem.txt").split("\n\n");
|
||||||
|
|
||||||
cx.render(rsx!(
|
cx.render(rsx!(
|
||||||
div {
|
div {
|
9
rust-letter-fe/src/main.rs
Normal file
9
rust-letter-fe/src/main.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
use rust_letter_fe::web_app;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// init debug tool for WebAssembly
|
||||||
|
wasm_logger::init(wasm_logger::Config::default());
|
||||||
|
console_error_panic_hook::set_once();
|
||||||
|
|
||||||
|
dioxus_web::launch(web_app::App);
|
||||||
|
}
|
31
src/main.rs
31
src/main.rs
@ -1,34 +1,7 @@
|
|||||||
#[macro_use]
|
use rust_letter_be::web_app_backend;
|
||||||
extern crate rocket;
|
|
||||||
|
|
||||||
use dioxus::core::VirtualDom;
|
|
||||||
use rocket::fs::FileServer;
|
|
||||||
use rocket_dyn_templates::{Template, context};
|
|
||||||
use rust_letter::web_app;
|
|
||||||
|
|
||||||
#[get("/")]
|
|
||||||
async fn index() -> Template {
|
|
||||||
let mut vdom = VirtualDom::new(web_app::App);
|
|
||||||
let _ = vdom.rebuild();
|
|
||||||
let output = dioxus_ssr::render(&vdom);
|
|
||||||
Template::render(
|
|
||||||
"index",
|
|
||||||
context! {
|
|
||||||
app_title: "A Letter For You!",
|
|
||||||
style_include: "<link href=/styles/tailwind.min.css rel=stylesheet />",
|
|
||||||
test: &output
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[rocket::main]
|
#[rocket::main]
|
||||||
async fn main() -> Result<(), rocket::Error> {
|
async fn main() -> Result<(), rocket::Error> {
|
||||||
let _result = rocket::build()
|
let _rocket = web_app_backend::build_rocket().await.launch().await;
|
||||||
.mount("/images", FileServer::from("public/images"))
|
|
||||||
.mount("/styles", FileServer::from("public/styles"))
|
|
||||||
.mount("/fonts", FileServer::from("public/fonts"))
|
|
||||||
.mount("/", routes![index]).attach(Template::fairing())
|
|
||||||
.launch()
|
|
||||||
.await;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user