759 words
4 minutes
Steam Family Sharing Library Preview — Deployment
2024-06-18
2024-07-31

Update, July 31, 2024:

I bought a Hong Kong server today, so this project is back up. The address is still www.steamhome.xyz, and the plan I laid out on the 26th is going ahead as well.


Update, July 26, 2024:

My GCP free-trial account (the one with $300 in credits) expired and the VM got shut down, which took the deployed service down with it. I don’t have any servers outside mainland China at the moment, so the live demo is offline. On the bright side, I realized Vercel’s KV Database can fill the role of a database for storing Steam keys, so I’m planning to rewrite the project with Next.js 14 (full-stack framework). Since Vercel’s KV Database doesn’t ship a visual management UI, here’s the plan:

  1. Build an open-source visual panel for Vercel KV Database with Next.js 14 and publish it on GitHub
  2. Rewrite the Steam family sharing library preview project with Next.js 14

Compared with the headaches on the server side and the client side, deployment turned out to be the most troublesome part of all.

The first wall I hit was the server’s network environment. All I had was a Tencent Cloud VM inside mainland China. After deploying the backend there, requests kept failing, and the service logs showed that calls to the Steam Web API were being rejected due to network restrictions. I asked ChatGPT for advice; it suggested routing the requests through a proxy, but there were no free, reliable proxies to be found. As it happened, I had just gotten the GCP $300 trial account around that time, so I spun up a GCP VM and set up a proxy on it — which, for reasons I never pinned down, still couldn’t reach the API. So I changed tack and deployed the service directly on the GCP VM.

Deploying on GCP#

First, follow this guide to set up the required environment.

  1. Install BT Panel (BaoTa)

The GCP VM has no hostname set by default, which breaks the installer. Set one and the installation goes through. Reference (Chinese)

  1. Get the code onto the server

I pushed the code to a private GitHub repository, generated an SSH key pair on the server, and registered the public key with GitHub.

  1. Start the backend service

After cloning the repo and installing the npm dependencies, manage the project through the “Website” menu in BT Panel.

Managing the project in BT Panel

This project also uses a database. At first I left MongoDB running without any credentials, and someone promptly wiped it and left a new database behind — the name basically said “pay us USDT to get your data back.” Luckily nothing important was stored there. Still, to keep it from happening again, database access control had to be turned on.

Enable access control

Edit MongoDB’s config file (usually /etc/mongod.conf) and enable authorization. Find the security section and make sure it reads:

security:
authorization: enabled

Enter the MongoDB shell

Terminal window
mongo
# or
mongosh

Create a user

use admin
db.createUser({
user: "adminUser",
pwd: "adminPassword",
roles: [ { role: "root", db: "steam-shared" } ] // grant this account access to the steam-shared database
})

Restart MongoDB

Terminal window
sudo systemctl restart mongod

Update the database connection

Configure the credentials:

module.exports = {
DB_HOST: 'localhost',
DB_PORT: 27017,
DB_NAME: 'steam-shared',
DB_USER: 'adminUser',
DB_PASS: 'adminPassword',
}

Connect:

const mongoose = require('mongoose');
const config = require('../config/db');
module.exports = (success, error) => {
mongoose.connect(`mongodb://${config.DB_USER}:${encodeURIComponent(config.DB_PASS)}@${config.DB_HOST}:${config.DB_PORT}/${config.DB_NAME}?authSource=admin`, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log('Database connection successful');
success();
})
.catch((err) => {
console.error('Database connection error:', err);
error(err);
});
};
  1. Deploy the client

Build the client with npm run build:prod, then serve the output folder as a BT Panel PHP site — just point the site’s root directory at the build folder.

Deploying the client in BT Panel

At this point the project should be reachable at ip, but that’s impossible to remember, which means it’s time for a domain. Registering a domain in mainland China requires ICP filing, so I bought a cheap one from an overseas registrar instead.

Domain purchased

From here it’s just DNS: add the records and the site becomes reachable at www.steamhome.xyz.

First, create a DNS zone in GCP.

Creating DNS resolution in GCP

Then add the records in the registrar’s DNS management.

Adding DNS records

Wait a few minutes and keep pinging the domain until it resolves.

Pinging the domain

Then add an A record in GCP.

Configuring the A record in GCP

The project itself needs the domain configured too.

Configuring the domain for the project

For example, before configuration the backend could only be reached at http://35.220.167.240:3001/api/tracking/data; afterwards it answers at http://api.steamhome.xyz/api/tracking/data.

Same story for the pages — they’re now reachable at www.steamhome.xyz.

SSL#

To serve the site over HTTPS, add an SSL certificate. BT Panel can provision a Let’s Encrypt certificate with one click.

Configuring the SSL certificate in BT Panel

Steam Family Sharing Library Preview — Deployment
https://www.mihouo.com/en/posts/front/steamshared/deployment/
Author
Jia
Published at
2024-06-18
License
CC BY-NC-SA 4.0