mkovaxx / rust-fullstack-demo

A fullstack Rust application demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rust-fullstack-demo

A fullstack Rust application demo

Running on Docker

First install Docker. You can find instructions here.

Next, install docker-compose. This will allow us to build and run several docker containers simultaneously. Instructions can be found here.

To run the docker container, you'll need file called docker.env to hold your environment variables. It's contents should look like this:

PGDATA=./database/data/

FRONTEND_HOST=localhost
FRONTEND_PORT=8000
FRONTEND_PROTOCOL=http

DATABASE_PROTOCOL=postgres
DATABASE_PORT=5432
POSTGRES_USER=ratebeer_app
POSTGRES_PASSWORD=passw0rd
POSTGRES_DB=ratebeer_clone
POSTGRES_HOST=database

BACKEND_HOST=backend
BACKEND_PORT=8080
BACKEND_PROTOCOL=http

Once everything is up and running, visit [http://localhost:8000] to view the app.

Running Outside Docker

Database Installation

This app requires a Postgres 14 database. Follow the steps in the article below which matches your operating system.

Downloads for the various operating systems can be found here

Windows

Refer to this article

After installation, open your terminal and try running "psql". If you find that the command isn't find, then you probably need to set some environment variables.

If you're running windows, you can follow the instructions in step 3 of this article.

Mac

Refer to this article

Linux

Refer to this article

Database Setup

Once you have a Postgres server up and running, create a database and make sure your database user as read and write privileges.

Example:

sudo -u postgres psql
create database rustfullstack;
create user rustuser with encrypted password 'password';
grant all privileges on database rustfullstack to rustuser;
exit

NOTE: If you get an error message saying "connection refused", your postgres server may have installed on port 5433 rather than the default 5432. To resolve this, try using the -p flag as follows:

sudo -u postgres psql -p 5433

ENV FILE

You'll need a .env file to define the various urls that the app needs to run. It should look like the following:

FRONTEND_HOST=localhost
FRONTEND_PORT=8000
FRONTEND_PROTOCOL=http

DATABASE_PROTOCOL=postgres
DATABASE_PORT=5432
POSTGRES_USER=ratebeer_app
POSTGRES_PASSWORD=password
POSTGRES_DB=ratebeer_clone
POSTGRES_HOST=localhost

BACKEND_HOST=localhost
BACKEND_PORT=8080
BACKEND_PROTOCOL=http

Running Database Migrations

Next we need to run the migrations to populate the database with tables and sample data.

From the root directory run the following:

cargo run --manifest-path ./database/migration/Cargo.toml

Running the App

The app consists of a frontend and a backend component. To run the backend, navigate to the backend folder and run cargo run

Any pending migrations will be executed on app startup.

The frontend is built using Webpack, so you'll need to install Node to run it.

Before running the app, you'll have to install the NPM packages. Navigate to the frontend folder and run npm install. You'll only have to do this once.

From the frontend folder run npm run dev to start the dev server.

Note: On Windows, you might see the following error:

<e> [webpack-dev-middleware] Error: spawn npm ENOENT
<e>     at ChildProcess._handle.onexit (node:internal/child_process:285:19)
<e>     at onErrorNT (node:internal/child_process:483:16)
<e>     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
<e>   errno: -4058,
<e>   code: 'ENOENT',
<e>   syscall: 'spawn npm',
<e>   path: 'npm',
<e>   spawnargs: [ 'install', '-g', 'wasm-pack' ]
<e> }

If you get this error, run the following command and then try again:

npm install -g wasm-pack

About

A fullstack Rust application demo

License:Apache License 2.0


Languages

Language:Rust 92.1%Language:JavaScript 3.0%Language:Dockerfile 2.8%Language:HTML 2.0%Language:SCSS 0.1%