## Prep steps
- Create directory structure
```
sudo mkdir -p /usr/local/toi/{api,sb-ws}
```
- Install ‘nginx’ on server
```
sudo apt install nginx
```
- Configure nginx  
Open /etc/nginx/sites-enabled/default  
Replace section  
```location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
```
with   
```location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.html;
        }
```
Add following section just before "location / { ..... }"
```
location ~* \.io {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;

    proxy_pass http://localhost:3000;
    proxy_redirect off;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

location /static/flags {
  # redirect missing team flags (logos) to this file
  try_files $uri /static/flags/unknown.png;
}

location /static/jerseys {
  # redirect missing jerseys to this file
  try_files $uri /static/jerseys/jersey_template.png;
}
```

- Check images for team flags (club logos) and team jerseys

These images are stored inside **app/static/flags** and **app/static/jerseys** directories, respectively.

The images are supposed to be automatically copied when you build the content for the web server, as described later in this README document.

The files are supposed to be of the PNG type (**.png** extension) and their name is supposed to match the lowercase Hydra's **team code**, e.g. *hcd.png* for *HC Davos* or *lat.png* for *Team Latvia*, likewise, *hcd_jersey.png* and *lat_jersey.png* for their jerseys.

- Restart nginx service
```
sudo systemctl restart nginx
```
- Install node.js server
```
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
```
- Install Yarn package manager
```
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
```
## Build && Install
- Install dependencies
```
cd ~/toi/app && yarn
cd ~/toi/api && yarn
cd ~/toi/sb-ws && git submodule update --init
```
- Build Game Time Service
```
apt install libssl-dev
apt install g++
apt install cmake
cd ~/toi/sb-ws
mkdir build; cd build
cmake ..
make -j
```
- Configuration

Generate 'secret'
```
openssl rand -base64 32
```
Edit IIHF Hydra Endpoint configuration and change 'secret' value with generated one
```
pico ~/toi/api/config/index.js
```
Edit Web App (UI) config, and change:
API_ENDPOINT - (Node.js APP IP & Port)
WS_ENDPOINT - (Game time Web Service)
CHAT_ENDPOINT - (Chat service endpoint)
```
pico ~/toi/app/config/prod.env.js
```
Build Web App (UI)
```
cd ~/toi/app && yarn build
```
Copy Web App to web server webroot
```
sudo cp -a ~/toi/app/dist/* /var/www/html/
```
Copy API
```
sudo cp -a ~/toi/api /usr/local/toi/
```
Copy Game Time Service
```
sudo cp -a ~/toi/sb-ws/build/sb-ws-service /usr/local/toi/sb-ws
```
## Starting
Start API Service
```
cd /usr/local/toi/api && yarn start
```
Start Game Time Service
```
cd /usr/local/toi/sb-ws
./sb-ws-service SCOREBOARDD_HOST SCOREBOARDD_PORT
```
