Here's an actix-web template that uses SvelteKit built and served as static files. With simple CRUD setup using Surreal DB as a permanent storage for application data (Todos).
We use Vite's proxy in the dev environment and serve svelte as static files in production.
curl https://sh.rustup.rs -sSf | sh
Install dependencies:
cd client && npm install
cd ..
npm install
Start docker img of SurrealDB:
docker run --rm --pull always --name surrealdb -p 8000:8000 -v ~/mydata:/mydata surrealdb/surrealdb:latest start file:/mydata/mydatabase.db --user root --pass root
Start actix backend and svelte frontend with one command (from root directory):
npm run dev
All traffic to localhost:3000/api/* will be forwarded to the actix web project, and anything else to the SvelteKit frontend.
You can build the project with cargo. The build.rs
will automatically compile the frontend to static files in the ./client/build directory.
cargo build --release
For convenience a Dockerfile was created which handles compiling the frontend to static files and building the Actix Web server into a 20mb Alpine image.
docker build -t actix-svelte-surreal .
docker run -d -p 8080:8080 actix-svelte-surreal