This repository was archived by the owner on Aug 7, 2024. It is now read-only.
Repository navigation
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.
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',
[...]
});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.localin 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)
We have a simple Ingress configuration that sends all the requests to the Nginx reverse proxy. The reverse proxy is exposed to the external network. Our configuration is identical to the single back-end on in the Ingress documentation for Kubernetes.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: aimmo-ingress
spec:
backend:
serviceName: aimmo-reverse-proxy
servicePort: 80