Selfhost the GameHub API Mirror
For this tutorial lets assume you already have a vps or a server with ubuntu or a similar linux distro installed. If you don't have a server, one cheap vps provider is https://racknerd.com/.
Tools we will be using in this tutorial
- Git
- Node.js & npm
- Curl (for testing)
- Nginx (optional)
- Certbot (optional)
Download the server files
Once you have opened your server console, go to the /opt folder:
cd /opt
and then clone the repository using git and navigate to the directory:
sudo git clone https://github.com/EmberNetwork/Mirror mirror && cd mirror
Configuring the server
Open config.json in your favorite command line editor. For this tutorial we will be using nano:
sudo nano config.json
The file should contain this content:
{
"port": 8080,
"netplay": {
"enabled": false,
"TWILIO_ACCOUNT_SID": "",
"TWILIO_AUTH_TOKEN": ""
}
}
The default port that the mirror server will try to run on is 8080 which if the server you are using is hosting other applications the ports may conflict. You can read about netplay and how to use it here.
Run the server
First install packages:
npm install
then start the server in production mode:
npm start
If you have other programs running on your server see more about running the mirror server in the background here.
Your mirror instance should be running on port 8080 or whatever port you set in the configuration. Try accessing the server using
curl http://localhost:8080
and you should get a response back that says something like this:
{"status":"ready","mode":"prod","version":"1.2.1","description":"A simple proxy server for the GameHub API","repository":"https://github.com/EmberNetwork/Mirror","netplay":{"enabled":false}}
Using nginx
To install nginx run these commands:
sudo apt update
sudo install nginx
then run:
sudo ufw allow "Nginx Full"
Now run this to create the mirror.conf file in /etc/nginx/sites-available/:
nano /etc/nginx/sites-available/mirror.conf
and copy this content, swapping your_domain_here with your domain, like api.gamehub.dev:
server {
listen 80;
listen [::]:80;
server_name YOUR_DOMAIN_HERE;
access_log /var/log/nginx/plausible.access.log;
error_log /var/log/nginx/plausible.error.log;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Now enable the site using:
ln -s /etc/nginx/sites-available/plausible.conf /etc/nginx/sites-enabled/
and test the nginx configuration with:
nginx -t
Then restart nginx
sudo systemctl reload nginx
Now check your domain to see if it is working. It should return something like this:
{"status":"ready","mode":"prod","version":"1.2.1","description":"A simple proxy server for the GameHub API","repository":"https://github.com/EmberNetwork/Mirror","netplay":{"enabled":false}}
Configuring HTTPS
We will now be configuring https with certbot
First install certbot:
sudo apt install certbot python3-certbot-nginx
then run:
certbot --nginx -d
https should be enabled on your server!
Happy Coding!