Giter VIP home page Giter VIP logo

g5api's Introduction

G5API - A Tournament Management API Backend for Get5

Status: Under active development.

G5API is a replacement for the get5-webpanel. This is the backend only, as it will allow the plugin to interface with a database, Steam OAuth, Local Logins, and API Keys, as well as make various calls to functionality that is seen in the get5-web.

If you would like a supplemental front-end, please see Get5Vue or use the docker-compose located in the repo!


Like The Project? Feel free to sponsor it! Click the Sponsor button on the repo to see all the possible ways of supporting this development!
Sponsor me

If you've donated and would like to have your name listed as a sponsor, please message me on Twitter!


What does it do?

G5API is an API that will allow users to create, manage, and control Counter-Strike: Global Offensive matches. Add teams, create matches, and most importantly, track statistics across matches, and create Seasons/Tournaments to track stats within date ranges.

This API is complete enough to provide the most functionality out of get5.

For the plugin G5WS, the routes currently put into place located in the ./routes/legacy/ and still point to /match/ on this app.

Game server interaction will still take place under the /matches/:match_id directive, but the logic can be found under ./matches/matchserver.js.

The webapi plugin for this can be downloaded from here to include the use of vetoes being recorded, as well as demoes being uploaded to the API server once the match is complete.

There is also Challonge integration within the API. If a user provides a tournament ID to create a season, it will auto-fill a season start date, empty teams, and will auto-update the brackets at the end of each match if the match exists under the Season/Tournament.

What does it NOT do?

This is simply a back-end to get myself used to JavaScript and Node. You will need a front end or create something that can make it work!

Why?

Get5-web is a now out-dated webpanel, with python2.7 being officially EOL. Being built all on Flask, with ORM (SQLAlchemy), and Jinja2, its tech spans more than a few years old. While it works really well for now, it is becoming increasingly harder to deploy to more modern hardware/software (such as Ubuntu 19) to ensure easy setup.

The intent will to be provide similar functionality with the use of NodeJS and Express, and this API will take care of session authentication as well, via the use of passport-steam, and rcon server commands via rcon, as well as more normalization in the database.

Building

In order to build this application, I've opted to use Yarn.

First you will need to copy over the development/test/production.json.template and update any values that are required. These include server values, and database passwords and connections. For more information, please see configuration.

If you wish to roll a production build, please copy production.json.template and fill out all the values.

To see initial configuration/installation on your server, please visit the wiki to learn more about first-time setup. Node, Redis, and MariaDB/MySQL are all pre-requisites, and the wiki will provide you with information on how to set it up, as well as some useful information about the templated configuration files.

Migrate dev database:

yarn migrate-create-dev && yarn migrate-dev-upgrade

You can specify which database to use in the development.json area. Please note that this will delete and recreate the development table. Also note that there are some tables that have changed. I've opted to normalizing the spectators and team authentication values, as BLOBS were not playing nicely with Node. My current fork deals with inserting into these tables, so I hope that it will eventually be a smooth transition where you can keep all your data from the old Flask app, if you so choose.

Migrate production database:

yarn migrate-create-prod && yarn migrate-prod-upgrade

This will attempt to update a production database by creating any tables that don't exist. It will not drop the database prior to importing new tables. If you are on windows, you will just have to create the database yourself, and then run yarn migrate-prod-upgrade.

Build and run:

yarn start

Spins up a development server (by default, please use the NODE_ENV variable to change this) where you can make all your calls. Since steam authentication is enabled, you will need to auth with Steam first before making any calls that would modify any data.

Docker Build Instructions:

This guide assumes you have a MariaDB or MySQL compatible server running. You can deploy one in docker following the MariaDB guide.

Build your docker image. Run the command docker build -t yourname\g5api:latest . Once this has finished, you can run the container using

docker container run --name g5api \
-p 3301:3301 \
-v redisVol:/RedisFiles \
-e PORT="3301" \
-e HOSTNAME="" \
-e DBKEY="" \
-e STEAMAPIKEY="" \
-e SHAREDSECRET="" \
-e CLIENTHOME="" \
-e APIURL="" \
-e SQLUSER="" \
-e SQLPASSWORD="" \
-e DATABASE="" \
-e SQLHOST="" \
-e SQLPORT="" \
-e ADMINS="" \
-e SUPERADMINS="" \
-e REDISPASSWORD="" \
-e UPLOADDEMOS="" \
yourname\g5api:latest

Docker Compose Instructions

This guide will get you to setup a running instance for a reverse proxy (Caddy), G5API, and G5V running all at once.
Provided in this repository is a docker-compose.yml file. Much like the above Docker run commands, all those fields are required in the docker file, as well as a few additional parameters.

  • CADDY_URL is the URL that you wish to host everything.
  • CADDY_REVERSE_PROXY_PORT is the port that the API is serving to. By default, this is set to 3301.
  • CADDY_API_ENDPOINT is the end point that you wish to route from. By default, this is api. This should only be swapped if you have a different G5V build you are pointing to.
  • And then your mysql information is required in that file as well.

Once those are all filled in, you need to run two more commands. The first being the network bridge, which is done via docker network create -d bridge get5. After this, you can simply run docker-compose up -d.This will spin up a production instance of Get5Vue, as well as Get5API, and a reverse proxy to link everything together!

For more details on these variables, follow along with production.json.template located in /config

Docs:

yarn doc

This will generate all the API information that I've created in the app, in the hopes of making it more readable and easier to pickup for anyone who wants to try more implementation, or even creating a front-end for this API. Swagger Express is also included, which can be accessed from /api-docs on application launch. This will house all the API calls, where JSDocs will show all the internal function calls in this application.

Coverage Tests

Steam OAuth will be mocked in order to check if a user is "logged in", and create a temporary database (get5test) that will insert new values, and check various features of routes. If you wish to alter the "user" it authenticates as, you can edit utility/mockProfile.js to the values you prefer.

yarn test

Will require test.json to exist in projects config folder. It will grab the value from ./utility/mockProfile.js to set it as a super_admin temporarily, then remove it after. These tests are mainly meant for CI, and will be the go-to to test if any changes break the application.

Contribution

If you have a knack for APIs and a penchant for JavaScript, I could always use help! Create a fork of this application, make your changes, and submit a PR. I will be using the Issues page to track what calls still need to be completed. Even though this project is "complete" in a sense of it does what is on the tin, I wouldn't be opposed to new features or suggestions on how to make the API better!

If you so choose to contribute, please make sure you include documentation for the API calls, as it is how I am keeping track of all the functionality. I'm using JSDoc as well as Swagger to provide documentation. Please read over some of the files to get accustomed to usage.

If you are creating a front-end for this, please create an issue and let me know, so I can append it to the README, so other users' will be able to easily track it down.

License

This project is licensed under MIT License. A copy of this license must be included with the software.

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.