From c029cd0d087ec538289048d1176c9113f50f5c32 Mon Sep 17 00:00:00 2001 From: Ada Werefox Date: Sat, 1 Apr 2023 15:28:15 -0500 Subject: [PATCH] Created workspace for seperate fe/be dev, updated README and Dockerfile. --- Cargo.toml | 21 ++--- Dockerfile | 17 +++- README.md | 85 ++++++++++++++----- Rocket.toml | 4 +- {src/data => data}/poem.txt | 0 public/styles/tailwind.min.css | 2 +- rust-letter-be/Cargo.toml | 20 +++++ rust-letter-be/src/lib.rs | 34 ++++++++ rust-letter-fe/Cargo.toml | 16 ++++ Dioxus.toml => rust-letter-fe/Dioxus.toml | 6 +- build.rs => rust-letter-fe/build.rs | 2 +- .../src}/components/.gitkeep | 0 {src => rust-letter-fe/src}/index.css | 0 {src => rust-letter-fe/src}/lib.rs | 5 +- rust-letter-fe/src/main.rs | 9 ++ {src => rust-letter-fe/src}/utils/.gitkeep | 0 .../tailwind.config.js | 0 src/main.rs | 31 +------ 18 files changed, 176 insertions(+), 76 deletions(-) rename {src/data => data}/poem.txt (100%) create mode 100644 rust-letter-be/Cargo.toml create mode 100644 rust-letter-be/src/lib.rs create mode 100644 rust-letter-fe/Cargo.toml rename Dioxus.toml => rust-letter-fe/Dioxus.toml (78%) rename build.rs => rust-letter-fe/build.rs (64%) rename {src => rust-letter-fe/src}/components/.gitkeep (100%) rename {src => rust-letter-fe/src}/index.css (100%) rename {src => rust-letter-fe/src}/lib.rs (96%) create mode 100644 rust-letter-fe/src/main.rs rename {src => rust-letter-fe/src}/utils/.gitkeep (100%) rename tailwind.config.js => rust-letter-fe/tailwind.config.js (100%) diff --git a/Cargo.toml b/Cargo.toml index 524f90c..4192793 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,21 +4,14 @@ version = "0.1.0" authors = ["Ada Werefox "] 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"] diff --git a/Dockerfile b/Dockerfile index bc65e9e..94f302a 100644 --- a/Dockerfile +++ b/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"] diff --git a/README.md b/README.md index 1300146..c737ade 100644 --- a/README.md +++ b/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 ``` diff --git a/Rocket.toml b/Rocket.toml index d762efc..00a6d26 100644 --- a/Rocket.toml +++ b/Rocket.toml @@ -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] diff --git a/src/data/poem.txt b/data/poem.txt similarity index 100% rename from src/data/poem.txt rename to data/poem.txt diff --git a/public/styles/tailwind.min.css b/public/styles/tailwind.min.css index bbc3cb4..80580ff 100644 --- a/public/styles/tailwind.min.css +++ b/public/styles/tailwind.min.css @@ -1 +1 @@ -/*! tailwindcss v3.2.7 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.container{width:100%}@media (min-width:640px){.container{max-width:640px}}@media (min-width:768px){.container{max-width:768px}}@media (min-width:1024px){.container{max-width:1024px}}@media (min-width:1280px){.container{max-width:1280px}}@media (min-width:1536px){.container{max-width:1536px}}.relative{position:relative}.mx-4{margin-left:1rem;margin-right:1rem}.mx-auto{margin-left:auto;margin-right:auto}.flex{display:flex}.hidden{display:none}.h-48{height:12rem}.min-h-screen{min-height:100vh}.w-48{width:12rem}.max-w-fit{max-width:-moz-fit-content;max-width:fit-content}@keyframes growshrink{0%{transform:scale(.5)}40%{transform:scale(1.2)}60%{transform:scale(1.2)}to{transform:scale(.5)}}.animate-growshrink{animation:growshrink 2s cubic-bezier(1,0,0,1) infinite}.flex-col{flex-direction:column}.justify-center{justify-content:center}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem*var(--tw-space-y-reverse))}.border-4{border-width:4px}.border-alice-werefox-red-dark{--tw-border-opacity:1;border-color:rgb(128 0 8/var(--tw-border-opacity))}.bg-alice-werefox-grey-light{--tw-bg-opacity:1;background-color:rgb(204 204 204/var(--tw-bg-opacity))}.bg-alice-werefox-grey-lightest{--tw-bg-opacity:1;background-color:rgb(238 238 238/var(--tw-bg-opacity))}.p-4{padding:1rem}.py-4{padding-top:1rem;padding-bottom:1rem}.py-8{padding-top:2rem;padding-bottom:2rem}.font-nerd{font-family:DejaVuSansMono}.text-alice-werefox-red-dark{--tw-text-opacity:1;color:rgb(128 0 8/var(--tw-text-opacity))}@font-face{font-family:DejaVuSansMono;src:url(/fonts/DejaVuSansMono.ttf)}@media (prefers-color-scheme:dark){.dark\:border-alice-werefox-red{--tw-border-opacity:1;border-color:rgb(201 52 57/var(--tw-border-opacity))}.dark\:bg-alice-werefox-grey{--tw-bg-opacity:1;background-color:rgb(36 36 36/var(--tw-bg-opacity))}.dark\:bg-alice-werefox-grey-dark{--tw-bg-opacity:1;background-color:rgb(18 18 18/var(--tw-bg-opacity))}.dark\:text-alice-werefox-red-light{--tw-text-opacity:1;color:rgb(224 133 135/var(--tw-text-opacity))}} \ No newline at end of file +/*! tailwindcss v3.3.0 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.container{width:100%}@media (min-width:640px){.container{max-width:640px}}@media (min-width:768px){.container{max-width:768px}}@media (min-width:1024px){.container{max-width:1024px}}@media (min-width:1280px){.container{max-width:1280px}}@media (min-width:1536px){.container{max-width:1536px}}.relative{position:relative}.mx-4{margin-left:1rem;margin-right:1rem}.mx-auto{margin-left:auto;margin-right:auto}.flex{display:flex}.h-48{height:12rem}.min-h-screen{min-height:100vh}.w-48{width:12rem}.max-w-fit{max-width:-moz-fit-content;max-width:fit-content}@keyframes growshrink{0%{transform:scale(.5)}40%{transform:scale(1.2)}60%{transform:scale(1.2)}to{transform:scale(.5)}}.animate-growshrink{animation:growshrink 2s cubic-bezier(1,0,0,1) infinite}.flex-col{flex-direction:column}.justify-center{justify-content:center}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem*var(--tw-space-y-reverse))}.border-4{border-width:4px}.border-alice-werefox-red-dark{--tw-border-opacity:1;border-color:rgb(128 0 8/var(--tw-border-opacity))}.bg-alice-werefox-grey-light{--tw-bg-opacity:1;background-color:rgb(204 204 204/var(--tw-bg-opacity))}.bg-alice-werefox-grey-lightest{--tw-bg-opacity:1;background-color:rgb(238 238 238/var(--tw-bg-opacity))}.p-4{padding:1rem}.py-4{padding-top:1rem;padding-bottom:1rem}.py-8{padding-top:2rem;padding-bottom:2rem}.font-nerd{font-family:DejaVuSansMono}.text-alice-werefox-red-dark{--tw-text-opacity:1;color:rgb(128 0 8/var(--tw-text-opacity))}@font-face{font-family:DejaVuSansMono;src:url(/fonts/DejaVuSansMono.ttf)}@media (prefers-color-scheme:dark){.dark\:border-alice-werefox-red{--tw-border-opacity:1;border-color:rgb(201 52 57/var(--tw-border-opacity))}.dark\:bg-alice-werefox-grey{--tw-bg-opacity:1;background-color:rgb(36 36 36/var(--tw-bg-opacity))}.dark\:bg-alice-werefox-grey-dark{--tw-bg-opacity:1;background-color:rgb(18 18 18/var(--tw-bg-opacity))}.dark\:text-alice-werefox-red-light{--tw-text-opacity:1;color:rgb(224 133 135/var(--tw-text-opacity))}} \ No newline at end of file diff --git a/rust-letter-be/Cargo.toml b/rust-letter-be/Cargo.toml new file mode 100644 index 0000000..5c20b8b --- /dev/null +++ b/rust-letter-be/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "rust-letter-be" +version = "0.1.0" +authors = ["Ada Werefox "] +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"] \ No newline at end of file diff --git a/rust-letter-be/src/lib.rs b/rust-letter-be/src/lib.rs new file mode 100644 index 0000000..ef8e9e8 --- /dev/null +++ b/rust-letter-be/src/lib.rs @@ -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: "", + test: &output + }, + ) + } + + pub async fn build_rocket() -> Rocket { + 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()) + } +} diff --git a/rust-letter-fe/Cargo.toml b/rust-letter-fe/Cargo.toml new file mode 100644 index 0000000..1ef4688 --- /dev/null +++ b/rust-letter-fe/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "rust-letter-fe" +version = "0.1.0" +authors = ["Ada Werefox "] +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" diff --git a/Dioxus.toml b/rust-letter-fe/Dioxus.toml similarity index 78% rename from Dioxus.toml rename to rust-letter-fe/Dioxus.toml index 74b1dd1..c863e83 100644 --- a/Dioxus.toml +++ b/rust-letter-fe/Dioxus.toml @@ -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 = [] diff --git a/build.rs b/rust-letter-fe/build.rs similarity index 64% rename from build.rs rename to rust-letter-fe/build.rs index 46daf68..f828241 100644 --- a/build.rs +++ b/rust-letter-fe/build.rs @@ -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"); diff --git a/src/components/.gitkeep b/rust-letter-fe/src/components/.gitkeep similarity index 100% rename from src/components/.gitkeep rename to rust-letter-fe/src/components/.gitkeep diff --git a/src/index.css b/rust-letter-fe/src/index.css similarity index 100% rename from src/index.css rename to rust-letter-fe/src/index.css diff --git a/src/lib.rs b/rust-letter-fe/src/lib.rs similarity index 96% rename from src/lib.rs rename to rust-letter-fe/src/lib.rs index 1809267..d6d5f95 100644 --- a/src/lib.rs +++ b/rust-letter-fe/src/lib.rs @@ -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 { diff --git a/rust-letter-fe/src/main.rs b/rust-letter-fe/src/main.rs new file mode 100644 index 0000000..f972957 --- /dev/null +++ b/rust-letter-fe/src/main.rs @@ -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); +} diff --git a/src/utils/.gitkeep b/rust-letter-fe/src/utils/.gitkeep similarity index 100% rename from src/utils/.gitkeep rename to rust-letter-fe/src/utils/.gitkeep diff --git a/tailwind.config.js b/rust-letter-fe/tailwind.config.js similarity index 100% rename from tailwind.config.js rename to rust-letter-fe/tailwind.config.js diff --git a/src/main.rs b/src/main.rs index c4a89b5..fdae2b2 100644 --- a/src/main.rs +++ b/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: "", - 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(()) }