-
Notifications
You must be signed in to change notification settings - Fork 62
Setup
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.
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
.
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
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.
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
Now we'll bring up the backend with
nx serve backend
Note: Here we're using the
nx <task> <project>
shorthand, which is equivalent tonx 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.
So, navigate to http://localhost:3000/auth/steam
and login via Steam. This will set an accessToken cookie for the localhost
domain in your browser. You can access it through browser tools (in Chrome dev tools, you find this in _Application > Storage > Cookies), or alternative use this Tampermonkey script.
Insert that in the "Authorize" dialogue in Swagger, or as the bearer token in your HTTP client. Requests to the API should now work (as in, not 401
), with anything specific to your user (e.g. /user/* endpoints) using your actual Steam info!
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