This is still a work in progress, since i'm learning Rust/Yew/Warp/Diesel as I code.
Yew setup
- Install WASM target with
rustup target add wasm32-unknown-unknown
- Diesel cli requires
sudo apt install default-libmysqlclient-dev libsqlite3-dev libpq-dev
- Then run
cargo install diesel_cli
-
Create .env file
echo "DATABASE_URL=postgresql://dev:dev@localhost:5432" >> .env
echo JWT_SECRET_KEY=secret >> .env
Note: there's now an example .env file that can be used
Note: The postgresql://... URI might be different
Autoreload with systemfd for the backend
cargo install systemfd cargo-watch
- change dir to "backend" dir then run
systemfd --no-pid -s http::5555 -- cargo watch -w . -w ../db -w ../frontend -x run
Note on the above command: -w specifies which files will be watched by cargo-watch
The frontend uses Trunk, that auto-reloads by default:
- cargo install trunk
Now there's a docker-compose file ready to be ran, simply run docker-compose up after setting up the .env file (example env file supplied).
Both the front and backend will be exposed.
Note: The default behaviour of the backend is to provide unsafe HTTP requests and cookies, set the DEV_ENV variable to false so the JWToken is set as Secure.
In the future I'll implement a Docker setup for easier deployment, for now, run
-
Frontend:
-
TRUNK_SERVE_PROXY_BACKEND=<backend server:port/api> trunk serve
-
Note: TRUNK_SERVE_PROXY_BACKEND env. variable is necessary because Trunk.toml [[proxy]] wasn't working well with Docker
If you want to change the default proxy (defaults to localhost), pass do
trunk serve --proxy-backend <backend URL>
.
-
-
-
Backend:
cargo run
Note: backend is expecting a DATABASE_URL env. var with a valid postgresql link
- improve API Response errors (example:
{ "error": "duplicate key value violates unique constraint \"recipe_recipe_name_key\"" }
should be{"error":"key <KEY> already exists"}
) -
Create a seperate 'user validation function', so there's no repeating code (*_route.rs files validate user credentials)done