This demonstrates how to use Rust as the single server and runtime needed to serve up a React Single Page Application (SPA) written in TypeScript backed by a Postgres DB and meilisearch search service.
The SPA talks to APIs on the Rust server, which talks to the Postgres DB or Search service.
We do not use another server for serving the React app (such as Node.js), rather the single Rust server serves up the statically generated React application files to the requesting client. We still use Node to compile the React SPA and generate its static files.
- Rust's Axum web application server framework
- Postgres DB with Rust's sqlx toolkit for client interaction and other DB utilities
- Meilisearch with its Rust SDK
- Docker Desktop and Compose
- Added Rust unit and integration tests for most Rust code
- A basic GitHub workflow defined to start our core services, run tests, run Rust's formatter (rustfmt), and run Rust's linter (clippy)
- Enforces the most strict linting and code formatting for Rust and TypeScript code configured in VSCode and GitHub Action workflow
- Basic logging and tracing enabled
- Proper environment variable support (with .toml config files in the .cargo directory)
- Automated DB schema creation and upgrade script execution
- Using Docker Desktop and Docker Compose (using the compose.yaml in the project's base directory) to easily automate the initalization and setup of the database and search services the application relies on. You can still roll your own Postgres and meilisearch local setup, but why?
- VSCode launch configurations for running and debugging
- And many more (i.e. db connection pooling, etc. etc.)
The instructions below assume you have the following installed locally:
- Git (v2.39.3+)
- Rust (v1.80+)
- Node (v20.16.0+)
- Docker Desktop (v4.32+)
- VSCode (v1.90+ with "rust-analyzer" and "ESLint" extensions installed). This is optional, but highly recommended.
Note: Postgres and meilisearch will automatically be installed and initialized by our automated local build process using Docker Compose and a local environment initialization script.
See the Dev Environment Setup section for instructions on how to install any of the above.
With those requirements fulfilled, see the Sync the Repo and Build the App section on how to build this project and run the app.
** Or QUICKSTART **
[ In a terminal ]
- git clone https://github.com/siryancealot-enterprises/rust-react-app-hello-world.git
- cd rust-react-app-hello-world
- cargo build
- cargo docker_up
- cargo init_repo
- cd my-react-ts-app
- npm install
- npm run build
- cd ..
- cargo run
[in your browser]