Here is how to make quakejs work local and remote simultaneously. It's pretty quick and easy surprisingly.
1. Set up port forwarding.
In my router I have public port 88 pointing towards quakejs docker IP with local port 80, and public port 27960 also pointing towards my quakejs docker IP with port 27960. The two ports here will correspond with the code below, you must use port 27960 for the game. I used public port 88 for actually accessing the game, but you can use anything you want except port 80. Port 80 may cause issues if your router's web interface is on port 80.
2. Edit your index.html
Open the quakejs docker console
Install a text editor of your choice
apt update && apt install nano
Open the index.html file
nano /var/www/html/index.html
At the end of the <script>, at the bottom of the file you will see how the game makes it's connection with "var args = [...]".
I have added some code that determines if the game is being run locally or remotely.
In my case, I have an afraid.org subdomain pointing towards my home IP.
You will want to make your file look like mine, just with your domain or home IP instead of MYDOMAIN.
I removed some of the comment lines so you will notice some lines starting with // are missing here, you don't need those.
window.addEventListener('resize', resizeViewport);
let locw = window.location.host // var for the web access IP+port, window.location.host returns the IP/domain+port from the address bar, such as "192.168.1.5:88" or "myquake.example.com:88"
let locg = window.location.host // same as above except for the game port
let regex = /:.*/
if (locg.includes("MYDOMAIN")) { locg = locg.replace(regex,"") } // replace MYDOMAIN with your domain (eg. myquake.example.com) or IP, do not remove the quotes. This modifies the var by removing the web access port. You do not need to make any further adjustments, the regex will handle whatever port you used without issue.
var args = ['+set', 'fs_cdn', locw, '+connect', locg]; // this line has been modified to use the above variables
args.push.apply(args, getQueryCommands());
ioq3.callMain(args);
};
3. Reload apache2
service apache2 reload
4. (Optional) Password protecting your game
From the quakejs docker console
Generate a username and password. The command will prompt you for a password after you run it. Replace USERNAME with a name of your choice.
htpasswd -c /etc/apache2/.htpasswd USERNAME
Enable .htaccess restrictions for /var/www/. This command just blindly modifies a specific line, I'm assuming you didn't make any major changes here yet so this should be fine.
sed -i '172s/None/All/' /etc/apache2/apache2.conf
(Alternatively, if you don't want to blindly edit the file, just open the file and go to the "<Directory /var/www/>" section and change "AllowOverride None" to "AllowOverride All".)
Create the .htaccess file in /var/www/
echo -e 'AuthType Basic\nAuthName "Password Required"\nRequire valid-user\nAuthUserFile /etc/apache2/.htpasswd' > /var/www/.htaccess
Restart apache
service apache2 reload
Done.
Note: Certain maps are missing textures, seems like just a quakejs quirk as the official site has the same problem.