Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Game API

Alexandru Dan edited this page Aug 30, 2017 · 9 revisions

The whole game API is registered inside the urls.py file:

    url(r'^api/code/(?P<id>[0-9]+)/$', views.code, name='aimmo/code'),
    url(r'^api/games/$', views.list_games, name='aimmo/games'),
    url(r'^api/games/(?P<id>[0-9]+)/$', views.get_game, name='aimmo/game_details'),
    url(r'^api/games/(?P<id>[0-9]+)/complete/$', views.mark_game_complete, name='aimmo/complete_game'),

The specific controller are found inside view.py.

Reverse proxy for Javascript

We use a JS reverse proxy exposed to the JS application, so we can easily access the resource URLs from Javascript.

    url(r'^jsreverse/$', 'django_js_reverse.views.urls_js', name='aimmo/js_reverse'),   

An example of resource access from JS is:

    $.ajax({
        url: Urls['aimmo/code'](id=GAME_ID),
        type: 'GET',
        [...]
    });

Nginx reverse proxy

We use a Nginx proxy behind an Ingress which allows web browsers to connect to games to receive the game state. More info can be found at the links here.

http {
    resolver 10.0.0.10;
    server {
        listen 80;
        location ~^/game/([0-9]+)/? {
            proxy_pass "http://game-$1.default.svc.cluster.local";
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
        }
    }
}

events {
}

The Nginx configurations works as follows:

  • each game is exposed to the internal network through Kube services, each having the host name http://game-<game-id>.default.svc.cluster.local in the specific routing tables
  • when a request arrives at the /game/<id> resource the proxy pass to arrive at the correct pod is received
  • the rest of the configuration requests upgrade in order to use the WebSockets protocol(which we use with the Socket.IO API)
Clone this wiki locally