Skip to content

Install Teem in production

Kumar Shubham edited this page Jul 28, 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
  teem-link-preview:
    image: krshubham/teem-link-preview
    restart: always

This configuration also includes a teem-link-preview server for giving access to contextual link information and also helps in making teem more accessible for the search engines. 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 @teemLinkPreview;
                etag on;
        }
 
        location @teemLinkPreview {
        
                set $teemLinkPreview 0;

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

                if ($http_user_agent ~ "teemLinkPreview") {
                        set $teemLinkPreview 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 $teemLinkPreview 0;
                }
        
                #resolve using Google's DNS server to force DNS resolution and prevent caching of IPs
                resolver 8.8.8.8;
 
                if ($teemLinkPreview = 1) {
            #setting prerender as a variable forces DNS resolution since nginx caches IPs and doesnt play well with load balancing
                        proxy_pass http://127.0.0.1:9090;
                }

                if ($teemLinkPreview = 0) {
                        rewrite .* /index.html break;
                }
        }
}
In case of any issues feel free to post in the gitter channel at [this](https://gitter.im/P2Pvalue/teem) place.
Clone this wiki locally