An open-source community-driven leaderboard backend for the upcoming leaderboards.gg. This repo is a proof-of-concept for switching to a C# with ASP.NET Core stack. The original backend, written in Go, can be found here.
- Website: https://leaderboards.gg
- Other Repos: https://github.com/leaderboardsgg
- Discord: https://discord.gg/TZvfau25Vb
- JSON REST API intended for the leaderboards.gg site
- C# with ASP.NET Core, .NET 6
- Docker containers for PostgreSQL hosting and management run via Docker Compose
On Windows, you will need to ensure that the core.autocrlf
setting in your git config is set to true. Most default installations for Git on Windows set this automatically, but it may be worth making sure you have it set. You can set this field locally for this project by running the following command:
git config core.autocrlf true
Or, since this is a great setting for Windows in general, you can set this in your global config:
git config --global core.autocrlf true
There are a couple options available for you to choose, depending on your OS.
If you are on Windows/are a beginner, this will likely be the easiest to use.
- Download Visual Studio 2022 (Community edition is free) or modify your existing install
- You must choose this version as we use the .NET 6 SDK which older versions do not support
- In the section where you choose your Workloads, select at least "ASP.NET and Web Development"
Once VS has set itself up, you'll have to explicitly tell it to not override our .editorconfig settings*. Go to Tools -> Customise -> Commands, pick "File" in the "Menu bar" item, then in the Add Command window, choose File -> Advanced Save Options, and finally, set that to "Current Setting". Screenshot below for a little extra clarity:
* VS saves files with
CRLF
, which isn't good for everyone else on Mac/Linux. We've already set explicit line endings in our .editorconfig, but VS overrides it by default.
That should be it! Any other requirements to set up and run the application should be a directed process through the IDE.
A few cross-platform editor choices would be:
- Monodevelop (IDE)
- Visual Studio Code (Code Editor)
- Other editors with Omnisharp integrations
After installing a code editor:
- Install support for
editorconfig
in your editor - Download the .NET 6 SDK for your platform
Try to avoid installing via snap; trying to get dotnet running was more pain than it's worth.
- After cloning this repo, run the command
dotnet restore
to install all required dependencies - You will likely want to set up Omnisharp for easier development with your editor
- In Visual Studio Code, you can simply install the C# extenstion (use this link or the editor UI)
- Other editors will need to follow instructions to install the Language Server on their system manually
We use Postgres, but have the ability to run .NET's in-memory DB as well instead, which allows quicker debugging. If you would like to use the latter, you can set USE_IN_MEMORY_DB
in your .env
file to true
, or not make a .env
file at all, then skip to the next section. If you would like to use the former, follow these instructions:
As mentioned above, we run Docker containers for the DB. After installing Docker Compose, run these commands in the project root:
cp example.env .env
sudo docker-compose (or docker compose) up -d
This starts up:
- Adminer which is a GUI manager for the databases
- The main Postgres DB
- The test Postgres DB
Using the default values provided in example.env
, input these values in Adminer for access:
Field | Value |
---|---|
System | PostgreSQL |
Server | db (for main) / db-test (for test) |
Username | admin |
Password | example |
Database | leaderboardsmain / leaderboardstest |
After opening the solution, right click the LeaderboardBackend
project and click "Set as Startup Project".
Press F5 or the green play button at the top of the IDE. Note: The first time running the app, the IDE will prompt you to trust the HTTPS development certs.
After expanding the LeaderboardBackend.Test
project, you should be able to select Test > Run All Tests
from the top of the top menu. Alternatively, you can use the Test Explorer by selecting Test > Test Explorer
.
You will need to trust the HTTPS development certs. On Windows/Mac, you can run the following command (from the .NET docs):
dotnet dev-certs https --trust
If you are on Linux, you will need to follow your distribution's documentation to trust a certificate.
- This chapter in the .NET docs covers how to generate and then trust the dev cert for service-to-service (e.g. cURLing) and browser communications on Ubuntu.
- Trusting certs on Fedora and other distros(??) are linked at the bottom of the chapter.
You can read this chapter if you'd like to clear all certs and start over.
Then run the following commands to run the DB migrations:
# Install project tools
dotnet tool restore
# Run migrations
cd LeaderboardBackend
dotnet ef database update
To run the application from the CLI, run the following command from the root of the project:
dotnet run --project LeaderboardBackend --urls https://localhost:7128 // dotnet watch run ... for hotfixing
The value provided to --urls
has to match what's listed under applicationUrl
in LeaderboardBackend/Properties/launchSettings.json
. As of this writing, it's https://localhost:7128
.
To run the tests, run the following commands from the root of the project:
cd LeaderboardBackend.Test
dotnet test
To debug with breakpoints, first call export VSTEST_DEBUG=1
before running a test. Doing this allows you to attach a debug process to hit breakpoints with.