Base template for a full stack server entirely in rust
This isn't easier than a lot of the other ways to build yew apps, but it's pretty good for deployment, uses https and lets you build structs that the client and server can share entirely in rust.
Run the ./build.sh in order to build the wasm files, before you push to github if you're going to deploy it with the docker file
How it works:
In the the root directory there are three rust projects
Yew, which is compiled with trunk to render a dist folder that contains the files needed to serve the frontend of the application on the browser
Server, which serves the files in the dist folder, and any other backend services
Shared, which contains serializable structures visible to both the yew and server, so that they can send and receive data between each other
build.sh
Builds the files needed for distribution in /yew/dist
Copies that dist to the server folder
Then builds the server and runs it to serves it on port 8080
To build and deploy on Google cloud run:
- Copy the code here, put it in a repository connected to your github account
- After editing the code, run build.sh before commiting it to your repo to use, to update the dist contents in the server directory with the up to date generated wasm code and static files of the yew application
- Create a google cloud account and a new project
- Enable the "cloud build api" for that project
- Create a new trigger in cloud build, referencing that project, set it to build with the dockerfile, set the build timeout to 1800 seconds, set the trigger invocation to manual
- Run the trigger and wait ~20 minutes for it to build
- Go to cloud run
- Create a service using the image created at the run step, click "allow unauthenticated invocations"
- Give it a minute, click on the link the service exposes to find the app on the web
To connect a service to a domain name:
- Buy a domain name on the google account associated with the gcp account
- On the cloud build click "manage custom domains"
- Add a mapping, add the service, the domains you own that google can see should be there, select the one you want
- Go to https://domains.google.com/registrar/ click "manage" for the domain you mapped the service to
- Go to the dns page and add the custom resource records it tells you to add
- Wait like an hour, the domain you connected it to will serve the app