Skip to content

Install Teem in production

Antonio Tapiador edited this page Jan 23, 2017 · 5 revisions

Teem has two parts, backend (SwellRT) and frontend (Teem app). In order to setup Teem, you need to install both parts.

Backend (SwellRT)

Teem is built on top of SwellRT

The easiest / more straightforward way to setup a funcional SwellRT is using Docker Compose

You can use the following docker-compose.yml file as reference

version: '2'
services:
  swellrt:
    image: p2pvalue/swellrt:${SWELLRT_VERSION}
    hostname: swellrt.teem.works
    restart: always
    depends_on:
      - mongo
    ports:
      - "127.0.0.1:9898:9898"
    volumes:
      - ./swellrt/config:/usr/local/swellrt/config
      - ./swellrt/log:/usr/local/swellrt/log
      - ./swellrt/sessions:/usr/local/swellrt/sessions
      - ./swellrt/avatars:/usr/local/swellrt/avatars
      - ./swellrt/attachments:/usr/local/swellrt/attachments
  mongo:
    image: mongo:latest
    restart: always
    volumes:
      - ./mongo:/data/db
  prerender:
    image: p2pvalue/docker-prerender
    restart: always
    ports:
      - "127.0.0.1:9830:3000"

This configuration also includes a Prerender image so your Teem is accesible by search engines and messaging apps

Run everything using

docker-compose up

Finally, you have to setup the proxy in your nginx

map $http_upgrade $connection_upgrade {                                                                                                                                                                      [78/284]
        default Upgrade;
        ''      close;
}

server {
        listen 80;
        listen [::]:80;

        server_name     swellrt.teem.works;
        rewrite     ^   https://$server_name$request_uri? permanent;
}

server {
        listen 443;
        listen [::]:443;

        server_name     swellrt.teem.works;

        # Remove header from proxy so SwellRT assets can be cached
        add_header Last-Modified "";

        ssl on;
        ssl_certificate /etc/letsencrypt/live/teem.works/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/teem.works/privkey.pem;

        ssl_session_timeout 5m;

        ssl_protocols SSLv3 TLSv1;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
        ssl_prefer_server_ciphers on;

        location / {
                proxy_pass http://127.0.0.1:9898/;
                proxy_set_header  X-Real-IP  $remote_addr;
                proxy_set_header  Host  $http_host;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection $connection_upgrade;
                proxy_buffering off;
                proxy_ignore_client_abort off;
                break;
        }
}

Frontend (Teem app)

Teem app are just files that are served through a web server.

First of all, download Teem to your server

git clone https://github.com/Grasia/teem.git
cd teem

Then, you have to configure the built. In the built, source files from src/ are put together and minimized so they are optimally served to the client browser

cp config.js.sample config.js
edit config.js

It is specially important to configure config.swellrt.host and config.swellrt.port to point to the address where you have already deployed SwellRT

Then, you have to build Teem

gulp build

Now, your files are ready to be served. They can be found in the www/ folder. Configure your web server to point to that directory. Here you can find a configuration example for nginx

server {
        listen 80;
        listen [::]:80; # IPv6 Support

        server_name     app.teem.works;

        rewrite     ^   https://$server_name$request_uri? permanent;
}

server {
        listen 443;
        listen [::]:443;

        server_name     app.teem.works;

        root /path/to/your/teem/www;
        index index.html;

        # Use letsencrypt! It is awesome
        # HTTPS everywhere!!
        ssl on;
        ssl_certificate /etc/letsencrypt/live/teem.works/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/teem.works/privkey.pem;

        ssl_session_timeout 5m;

        ssl_protocols SSLv3 TLSv1;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
        ssl_prefer_server_ciphers on;

        location / {
                try_files $uri @prerender;
                etag on;
        }
 
        location @prerender {
                #proxy_set_header X-Prerender-Token YOUR_TOKEN;
        
                set $prerender 0;

                if ($http_user_agent ~* "baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator|WhatsApp") {
                        set $prerender 1;
                }

                if ($http_user_agent ~ "Prerender") {
                        set $prerender 0;
                }


                if ($uri ~ "\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff)") {
                        set $prerender 0;
                }
        
                #resolve using Google's DNS server to force DNS resolution and prevent caching of IPs
                resolver 8.8.8.8;
 
                if ($prerender = 1) {
            
                        #setting prerender as a variable forces DNS resolution since nginx caches IPs and doesnt play well with load balancing
                        set $prerender "127.0.0.1:9830";
                        rewrite .* /$scheme://$host$request_uri? break;
                        proxy_pass http://$prerender;
                }

                if ($prerender = 0) {
                        rewrite .* /index.html break;
                }
        }
}
Clone this wiki locally