# proxy This proxy is based on NGINX. The NGINX configuration is generated by a simple Node.js script which parses the docker socket. NGINX acts as a reverse proxy server. The Node.js script reads the docker socket file to generate a configuration for each running docker container. The base template for configuration is `nginx.conf.template` All `*.template` files are written with [mustache-js](https://github.com/janl/mustache.js "GitHub") syntax. The templates are assembled by the Node.js program. ## Docker Mapping The Node.js script reads out the `/var/run/docker.sock` to get the containers of the host system via [dockerode](https://github.com/apocas/dockerode "GitHub"). **Important:** The proxy expects your backend containers to provide following structure: * `stapps.version`-label of docker container to be set to a valid active version. See configuration.... * Service name for the backend container should be `backend` in docker-compose.yml. If you don't use docker-compose set `com.docker.compose.service`-label to `backend`. * The proxy container to run with `--net="host"` * A port exposed to the host machine. If you want to expose it only to the host machines internal loopback use following syntax: `127.0.0.1:3000-3500:3000` in docker-compose or docker ports configuration. This will attach the internal 3000 port to the host's loopback on any port between 3000-3500. The proxy will see in the docker.sock which port and ip was chosen. Internal loopback should be 127.0.0.1 tho. ## Configuration (Status Codes) Config files can be added by multiple universities (adding files like `config/default-b-tu`) and selected via the `NODE_APP_INSTANCE` environment variable. - OutdatedVersions return a `HTTP 404` - ActiveVersions return a `HTTP 503` if currently unavailable or the given code by running backend-node - Unsupported versions (not configured as outdated or active) return a `HTTP 404` - No version header given returns a `HTTP 300` **NOTE:** The default configuration expects the client to set a version header: `X-StApps-Version=` ## Logger The proxy uses [@stapps/logger](https://gitlab.tubit.tu-berlin.de/stapps/logger). You can provide `NODE_ENV=production` and SMTP-Configuration via environment-variables for monitoring in production use. # Usage Without ssl: ```sh docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --net="host" gitlab-registry.tubit.tu-berlin.de/stapps/proxy/master ``` With ssl: ```sh docker run --rm --net="host" \ -v /var/run/docker.sock:/var/run/docker.sock \ -v :/etc/nginx/certs/ssl.crt \ -v :/etc/nginx/certs/ssl.key \ gitlab-registry.tubit.tu-berlin.de/stapps/proxy/master ``` # Static Folder (docker run option: `-v :/static`) Der Zugriff erfolgt über: `http(s):///_static/` Beispiel Proxy auf Localhost für die Datei `static/test.json`: `http://localhost/_static/test.json` ## Bilder im Static Folder Bilder sollten folgendermaßen abgelegt und benannt werden: `//-.[jpg|png|gif]` Beispiel: `_static/images/Place/hautpmensa-thumbnail.jpg` Aufgerufen wird das mit: 'https://server.deiner.uni.de/_static/images/Place/hauptmensa-thumbnail' Bildgrößen sind: thumbnail, small, medium, large