Skip to content
Tom Ashford edited this page Jun 5, 2023 · 12 revisions

Whilst this repo contains some quite daunting moving parts, our Docker setup and build tooling should make setup relatively straightforward. The two things you'll need to install are

You will of course need Git installed, along with a terminal that you're comfortable using.

Please note, some scripts may require Unix-like coreutils such as rm, ls, cd etc. We do not use rimraf. If on Windows, the easiest thing to do is install Git Bash along with Git for Windows.

Docker

We use Docker to handle major services required by the backend. Currently, these are

  • PostgreSQL - a relation database
  • MinIO - an S3-compatible object (file) store

Our Docker Compose setup is configured to handle these for easy development. Simply run:

docker compose up -d

That will pull images for the services and start them up in containers. Note, if you wish to run these locally you can, but is OS-dependent. Just make sure to configure the services with settings corresponding to those in env.TEMPLATE.

Node

Next, install Node dependencies with

npm install

This will install dependencies for all projects in the monorepo, so is quite sizable (~1.1GB at time of writing). It will also establish commit hooks, which will perform formatting and linting after commits, and generate a copy of the Prisma client, which is essentially a set a type definitions mapping to the database schema.

Additionally, as we will be using Nx for our command execution, it's easiest to install globally with

npm install -g nx

Environment Variables

In the website directory copy the env.TEMPLATE to the same directory, rename it .env, and then add your configuration.

Only STEAM_WEB_API_KEY needs to be updated for basic development.

Docker will expose the ports of several containers, if using the default passwords in the env.TEMPLATE file, you should not be forwarding them to the Internet.

Running Applications

Database

We should have a running Postgres database and Prisma installed, so lets push our schema to the database, using

nx run db:push

Additionally, if you want to populate the database with mock data (good if you're doing frontend work), run

nx run db:seed

Backend

Now we'll bring up the backend with

nx serve backend

Note: Here we're using the nx <task> <project> shorthand, which is equivalent to nx run <project>:<task>.

For a quick guide to the Nx CLI see, https://nx.dev/core-features/run-tasks#running-tasks. For a general reference, see https://nx.dev/reference/commands.

This will compile and launch Nest, after which it'll serve endpoints are http://localhost:3000/. Swagger documentation (which was just autogenerated from the backend source) is available at http://localhost:3000/api-docs.

The majority of the API is locked behind auth, so to query endpoints through Swagger's (or cURL, Hoppscotch, Postman etc.) you'll need a Steam auth token. Unfortunately this process is a little complicated: our OpenID strategy means we cannot send the token back in a body, and for security reasons we don't include it in the redirect URL, so we send it as a cookie. This will set an accessToken cookie in your browser (in Chrome dev tools, you find this in Application > Storage > Cookies). Copy that value and insert in the "Authorize" dialogue in Swagger, or as the bearer token in your HTTP client. Alternative, you can use this Tampermonkey script.

Frontend

Launching the frontend is simple, just run

nx serve frontend

and navigate to http://localhost:4200.

To build for production, run:

nx build frontend

serve runs in development by default, build in production. For more control do e.g. nx run frontend:build:dev