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>"]
|
||||
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
|
||||
|
||||
[dependencies]
|
||||
dioxus = "0.3.2"
|
||||
dioxus-ssr = "0.3.0"
|
||||
rust-letter-be = { path = "./rust-letter-be" }
|
||||
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
|
||||
|
||||
COPY Cargo.toml .
|
||||
COPY data/ data/
|
||||
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 templates/ templates/
|
||||
COPY Cargo.toml .
|
||||
COPY Rocket.toml .
|
||||
|
||||
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
|
||||
|
||||
### Just build
|
||||
> This project works by using a Cargo workspace with two projects `rust-letter-fe` and `rust-letter-be`
|
||||
|
||||
```
|
||||
cargo build
|
||||
```
|
||||
### Backend
|
||||
|
||||
### Start a `dev-server` for the project:
|
||||
You can develop the backend by simply running the project from the root directory
|
||||
|
||||
```
|
||||
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`.
|
||||
|
||||
```
|
||||
docker build -t letter-werefox-cafe .
|
||||
docker run -p 3469 -d -t letter-werefox-cafe
|
||||
docker build -t rust-letter-werefox-cafe
|
||||
docker run -p 3469 -d -t rust-letter-werefox-cafe
|
||||
```
|
||||
|
||||
Or, run through docker compose.
|
||||
@ -50,11 +86,18 @@ docker compose up --build -d
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
.project
|
||||
- public # save the assets you want include in your project.
|
||||
- src # put your code
|
||||
- - utils # save some public function
|
||||
- - data # text files that will be read to for data in the app
|
||||
- - components # save some custom components
|
||||
- - templates # put template files here, right now just using handlebar
|
||||
.dioxus-letter-werefox-cafe
|
||||
|- data # text files that will be read to for data in the app
|
||||
|- public # save the assets you want include in your project.
|
||||
|- rust-letter-be
|
||||
|\
|
||||
||- src # source code folder for backend
|
||||
|- 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]
|
||||
address = "0.0.0.0"
|
||||
port = 3469
|
||||
# workers = 16
|
||||
# max_blocking = 512
|
||||
# keep_alive = 5
|
||||
@ -13,7 +13,7 @@ ident = "rust-letter-werefox-cafe"
|
||||
port = 8234
|
||||
|
||||
[release]
|
||||
port = 3469
|
||||
address = "0.0.0.0"
|
||||
secret_key = "yqXUwxWOGD6X7yZaMbRnOXsNjiDMicveyC2imK48KbM="
|
||||
|
||||
# [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"
|
||||
|
||||
# resource (public) file folder
|
||||
asset_dir = "public"
|
||||
asset_dir = "../public"
|
||||
|
||||
[web.app]
|
||||
|
||||
@ -24,13 +24,13 @@ title = "A Letter For You!"
|
||||
reload_html = true
|
||||
|
||||
# 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
|
||||
[web.resource]
|
||||
|
||||
# CSS style file
|
||||
style = ["tailwind.min.css"]
|
||||
style = ["styles/tailwind.min.css"]
|
||||
|
||||
# Javascript code file
|
||||
script = []
|
@ -1,7 +1,7 @@
|
||||
fn main() {
|
||||
let mut tailwind = std::process::Command::new("npx");
|
||||
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(" "),
|
||||
);
|
||||
tailwind.env("NODE_ENV", "production");
|
@ -1,7 +1,8 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
pub mod web_app {
|
||||
// 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 {
|
||||
cx.render(rsx!(
|
||||
@ -36,7 +37,7 @@ pub mod web_app {
|
||||
}
|
||||
|
||||
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!(
|
||||
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]
|
||||
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
|
||||
},
|
||||
)
|
||||
}
|
||||
use rust_letter_be::web_app_backend;
|
||||
|
||||
#[rocket::main]
|
||||
async fn main() -> Result<(), rocket::Error> {
|
||||
let _result = 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())
|
||||
.launch()
|
||||
.await;
|
||||
let _rocket = web_app_backend::build_rocket().await.launch().await;
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user