Coder Social home page Coder Social logo

mkovaxx / rust-fullstack-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from toadslop/rust-fullstack-demo

0.0 0.0 0.0 178 KB

A fullstack Rust application demo

License: Apache License 2.0

JavaScript 2.96% Rust 92.07% HTML 2.01% Dockerfile 2.81% SCSS 0.15%

rust-fullstack-demo's Introduction

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

rust-fullstack-demo's People

Contributors

bnheise avatar toadslop avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.