Coder Social home page Coder Social logo

button-game-api's Introduction

Button Game API

This is a backend designed for Button Game.

API

URL METHOD DESCRIPTION PARAMETERS
/api/ GET Root of api future documentation NONE
/api/v1.0/players/ GET Get one player if username exists else all players username
/api/v1.0/click/ POST Send click to server with 'username' in body NONE
/api/v1.0/needed-clicks/ GET Get next goal and amount of clicks needed NONE

Installation guide

NOTE: Most of these commands need to be run with root or sudo.

Install needed programs:

apt-get install mariadb-server nginx

Install needed libraries for python:

pip3 install flask flask-cors pymysql uwsgi

Installer can be downloaded by clicking this link.

or with:

wget https://dl.meckl.in/button-game-api/install.py

But first you need to create a directory and a database with a user for this.

Access the mysql with your root and its password (set in the installation of mariadb)

mysql -u root -p

Create database and a user for it.

CREATE DATABASE button_game;
GRANT ALL PRIVILEGES ON button_game.* TO 'api-user'@'localhost' IDENTIFIED BY 'very nice password';
FLUSH PRIVILEGES;

Now create a directory that will contain the api software itself.

mkdir /var/www/button-game-api

Now you should copy your just downloaded installer with wget:

cp install.py /var/www/button-game-api/install.py

or download it now:

cd /var/www/button-game-api
wget https://dl.meckl.in/button-game-api/install.py

Now you are ready to install!

Run the installer:

python3 install.py

And give the installer all the needed stuff that you just set up.

If you are using something else than Ubuntu, you should add this line in your config/uwsgi.ini file below module = wsgi:

plugins = logfile, python36

Replace python36 with python35 if you are using python3.5 and so on.

Create a new service to run the API:

nano /etc/systemd/system/button-game-api.uwsgi.service

Paste this inside with your own directories.

[Unit]
Description=uWSGI Backend for Button Game
After=syslog.target

[Service]
WorkingDirectory=/var/www/button-game-api
# Can require modifying, based on uwsgi installation directory
ExecStart=/usr/bin/uwsgi --ini config/uwsgi.ini
# Requires systemd version 211 or newer
RuntimeDirectory=uwsgi
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

Enable the service:

systemctl daemon-reload

Start the service:

service button-game-api.uwsgi start

If everything went right (without errors) you can now start to setup Nginx.

nano /etc/nginx/uwsgi_params

And paste parameters from this page .

Create configuration for Nginx:

nano /etc/nginx/sites-available/button-game-api.conf

And fill it with this:

server {
    listen 80;
    server_name api.example-game.com www.api.example-game.com;
    root /var/www/button-game-api/;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/var/www/button-game-api/config/uwsgi.sock;
    }
}

Enable your configuration:

ln -s /etc/nginx/sites-available/button-game-api.conf /etc/nginx/sites-enabled/button-game-api.conf

Test that your configuration works:

nginx -t

If it works:

service nginx reload

Or:

service nginx restart

Now setup your domain to point to your servers IP-address.

To fix permission issues (caused byt using root or sudo):

cd ..
chown www-data:www-data button-game-api/ -R

Setup SSL (optional)

Download certbot (if you are using something other than Ubuntu 14.04 - 18.04, installation guide can be found here):

apt-get update
apt-get install software-properties-common
add-apt-repository universe
add-apt-repository ppa:certbot/certbot
apt-get update
apt-get install certbot python-certbot-nginx

Get SSL certificates from Let's Encrypt:

certbot --nginx

Now select your newly created site.

button-game-api's People

Contributors

natsku123 avatar

Watchers

James Cloos 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.