How to switch to server-side saving for privately hosted?
After battling with this, I got it working privately hosted on my own server. (hooray!)
Working great so far! So how do I switch from cookie saves to the server-side save to the DB with user accounts?
Thanks!
npm run start instead of npm run start:dev. You can deduce it by looking at the JS codebase
Odd, because I am not running start:dev. I am using pm2 to autostart/daemonize npm, and explicitly have it running "npm run start"
Ill have to look at it later this afternoon and triple check.
On Sun, May 26, 2024, 7:20 AM Krystian Chmura @.***> wrote:
npm run start instead of npm run start:dev. You can deduce it by looking at the JS codebase
— Reply to this email directly, view it on GitHub https://github.com/pagefaultgames/rogueserver/issues/22#issuecomment-2132183008, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE5ITOYATLH5KUOGWMQDRL3ZEHARFAVCNFSM6AAAAABIJLH3Q6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZSGE4DGMBQHA . You are receiving this because you authored the thread.Message ID: @.***>
I've also launched my container via npm run start and it's not switching to user account mode, only cookie save. Any help would be appreciated.
docker-compose of my stack (only server and db):
name: pokerogue
services:
server:
command: --debug --dbaddr db --dbuser pokerogue --dbpass pokerogue --dbname pokeroguedb
image: rogueserver
restart: unless-stopped
depends_on:
db:
condition: service_healthy
networks:
- pokerogue
ports:
- "8001:8001"
db:
image: mariadb:11
restart: unless-stopped
healthcheck:
test: [ "CMD", "healthcheck.sh", "--su-mysql", "--connect", "--innodb_initialized" ]
start_period: 10s
start_interval: 10s
interval: 1m
timeout: 5s
retries: 3
environment:
MYSQL_ROOT_PASSWORD: admin
MYSQL_DATABASE: pokeroguedb
MYSQL_USER: pokerogue
MYSQL_PASSWORD: pokerogue
volumes:
- database:/var/lib/mysql
networks:
- pokerogue
volumes:
database:
networks:
pokerogue:
For the web server, I created a separate container on the same network, with port 8000 exposed, with a volume pointed to a clone of pagefaultgames/pokerogue, with Node 18 installed, running npm run start.
@mjferrante83 @fatmagic my setup is super easy
This repo:
docker-compose -f docker-compose.Development.yml up -d db
go run ./rogueserver.go
and the game
npm install
npm run start
For the web server, I created a separate container on the same network, with port 8000 exposed, with a volume pointed to a clone of pagefaultgames/pokerogue, with Node 18 installed, running npm run start.
Check those nasty lines here:
https://github.com/pagefaultgames/pokerogue/blob/5f82449120b16290a812ac964e38f0327c33e245/src/utils.ts#L234C1-L237C73
Theory: maybe due to in-docker deployment the isLocal flag is not true?
Thanks for the response @slsyy
Part of my problem is related to the ENV variable VITE_BYPASS_LOGIN not being set as I just cowboy'd making a custom container for this. After setting this ENV variable within my container to -1 and I am now provided with a login/registration prompt.
Unfortunately, every time I try to register a user -- it just takes me to a perpetual Loading screen. This is the same behavior I was getting when I trying to utilize ceramicwhite/pokerogue & ceramicwhite/rogueserver that's on DockerHub.
I've dived into the MariaDB container and can confirm the rogueserver container is communicating with it as it built the Database and Tables. Something tells me that the web container and the rogueserver container are having trouble communicating.
Some further testing I've done:
Modifications to /src/utils.ts: export const sessionIdKey = "pokerogue_sessionId"; export const isLocal = true; export const serverUrl = "http://172.18.0.3:8001"; export const apiUrl = "http://172.18.0.3:8001";
Testing connection from web container to rogueserver container: root@cca687c32bf2:/pokerogue# nc -zv 172.18.0.3 8001 Connection to 172.18.0.3 8001 port [tcp/*] succeeded! root@cca687c32bf2:/pokerogue# hostname -I 172.18.0.4
Output from MariaDB container watching via watch -n .2 mariadb-admin -padmin processlist:
Every 0.2s: mariadb-admin -padmin processlist f2529e9afc9e: Sun May 26 15:25:14 2024
+-----+-----------+------------------+-------------+---------+------+----------+------------------+----------+ | Id | User | Host | db | Command | Time | State | Info | Progress | +-----+-----------+------------------+-------------+---------+------+----------+------------------+----------+ | 5 | pokerogue | 172.18.0.3:34986 | pokeroguedb | Sleep | 9 | | | 0.000 | | 841 | root | localhost | | Query | 0 | starting | show processlist | 0.000 | +-----+-----------+------------------+-------------+---------+------+----------+------------------+----------+
Still the same issue even when forcing the consts pointing to the rogueserver container with a verified open port on 8001. MariaDB shows the rogueserver maintaining DB connection with the Sleep timer randomly resetting.
Any further assistance would be much appreciated. Thank you!
@mjferrante83 two things:
- you don't need to check the
server -> dbconnection. On start theservertries to apply database setup so you would see any problem in logs - have you checked chrome dev tools? Check, if frontend generates HTTP requests and verify correctness of
host:port
- have you checked chrome dev tools? Check, if frontend generates HTTP requests and verify correctness of
host:port
Ahhh good idea. Here is what is reported on registration attempt:
utils.ts:287 POST http://172.18.0.3:8001/account/register net::ERR_CONNECTION_TIMED_OUT (anonymous) @ utils.ts:287 apiPost @ utils.ts:276 submitAction @ registration-form-ui-handler.ts:81 (anonymous) @ form-modal-ui-handler.ts:94 emit @ phaser.js:201 processDownEvents @ phaser.js:104318 update @ phaser.js:104031 updateInputPlugins @ phaser.js:102744 onMouseDown @ phaser.js:102945 onMouseDown @ phaser.js:116461 Show less main.ts:25
TypeError: Failed to fetch
at utils.ts:287:5
at new Promise (
Uncaught (in promise)
TypeError: Failed to fetch
at utils.ts:287:5
at new Promise (
It doesn't appear to be able to reach http://172.18.0.3:8001/account/register despite me knowing I have a successful communication to that IP and Port via tests with nc -zv 172.18.0.3 8001
UPDATE: I figured it out -- I thought the networking between the web container and rogueserver container was isolated between each other, and thus it would make calls between each other on its local network... but looking at the data I saw in the Chrome Dev Tool I determined that the API calls needed to point to my exposed local host port for the rogueserver container (not the local IP for that container).
I am good to go! I appreciate the assistance :D
UPDATE: I figured it out -- I thought the networking between the web container and rogueserver container was isolated between each other, and thus it would make calls between each other on its local network... but looking at the data I saw in the Chrome Dev Tool I determined that the API calls needed to point to my exposed local host port for the rogueserver container (not the local IP for that container).
I am good to go! I appreciate the assistance :D
@mjferrante83 - Ok, so did you just manually change the server and API calls in utils.ts to your local 'rogueserver' and then it worked? I'm a complete newb at this, and could barely follow what you guys were doing up above. I and am trying to figure out how to get it talking properly for registration instead of cookies.
I did check Chrome Dev tools (without making changes to utils.ts) and it's complaining about CORS policies... which seems scary to me if I want to expose this server to the public for friends to play on. I don't want to have to expose the 'rogueserver' to the public if possible, just the PokeRogue app (on port 8000) so friends/family can play on my local setup.
Thank you for any advice... !
p.s. I am self-hosting "pokerogue" and "rogueserver" on the same VM, it's not using Docker or Containers. So the IP is the same for both (172.20.65.15 port 8000 and 8001)
@fatmagic -- What kind of setup are you going for?
Are you trying to run this whole app in Docker? If so, how? Did you build the container yourself or are you using someone else's solution?
The solution that worked for me was to build the web container from scratch with everything I learned about what this game needed. I run a single node Docker Swarm configuration so some of my setup required accounting for how Docker Swarm handles compose files and networking.
For the web container, I created this Dockerfile:
FROM debian:latest
# Set environment variables
ENV VITE_BYPASS_LOGIN=-1
ENV VITE_BYPASS_TUTORIAL=0
ENV PATH=/root/.nvm/versions/node/v18.20.3/bin:$PATH
# Install curl and NVM
RUN apt-get update && apt-get install -y \
curl \
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash \
&& export NVM_DIR="$HOME/.nvm" \
&& [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" \
&& [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" \
&& nvm install 18 \
&& nvm use 18 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /pokerogue
Notice the environment variables set in the Dockerfile. This one in particular -- ENV VITE_BYPASS_LOGIN=-1 -- is what changes the application from single user to managed account.
Now this Dockerfile itself won't cut it as it doesn't run anything in particular. Since I want some granularity on how the app spins up, I created an entrypoint.sh file that just runs "npm start" that I transpose into the container via the Volumes function of the compose file. Here's the relevant bits from my compose file. You can ignore the label portion if you are not using Traefik reverse proxy -- though you will need to add a Ports area and define 8000.
web:
image: mjferrante/pokerogue:latest
entrypoint: ["/pokerogue/entrypoint.sh"]
deploy:
restart_policy:
condition: on-failure
max_attempts: 3
labels:
- "traefik.enable=true"
- "traefik.docker.network=proxy"
- "traefik.http.services.pokerogue.loadbalancer.server.port=8000"
# TLS
- "traefik.http.routers.pokerogue.rule=Host(`pokerogue.REDACTED`)"
- "traefik.http.routers.pokerogue.entrypoints=https"
- "traefik.http.routers.pokerogue.tls=true"
networks:
- proxy
- pokerogue
volumes:
- ~/prod/pokerogue/repo/pokerogue:/pokerogue
- ~/prod/pokerogue/entrypoint.sh:/pokerogue/entrypoint.sh
tty: true
stdin_open: true
I have the pagefaultgames/pokerogue Git repo cloned to my host and created a volume in the container pointing to it. This allows me to easily Git Pull any update to my instance.
@slsyy pointed out some lines of code in the /src/utils.ts file what were also relevant to my situation:
export const sessionIdKey = "pokerogue_sessionId";
// Check if the current hostname is 'localhost' or an IP address, and ensure a port is specified
export const isLocal = (
(window.location.hostname === "localhost" ||
/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/.test(window.location.hostname)) &&
window.location.port !== "") || window.location.hostname === "";
// Set the server URL based on whether it's local or not
export const serverUrl = isLocal ? `${window.location.hostname}:${window.location.port}` : "";
export const apiUrl = isLocal ? serverUrl : "https://api.pokerogue.net";
As I have a reverse proxy between my containers and my outside web interface that also handles my SSL cert, I was always going to need a custom solution to this. I wrote a BASH script that updates my local Git repo that will use sed to evaluate these lines of code and rewrite them as I need them to be (basically hardcoding my networking information):
#!/bin/bash
REPO_FOLDER=~/prod/pokerogue/repo/pokerogue
# Reset and update local PokeRogue repository
git -C $REPO_FOLDER reset HEAD --hard
git -C $REPO_FOLDER pull
# Modify ./src/utils.ts for local configuration
sed -i '/\/\/ Check if the current hostname/,+6c export const isLocal = true;' $REPO_FOLDER/src/utils.ts
sed -i 's#^export const serverUrl.*#export const serverUrl = "REDACTED";#' $REPO_FOLDER/src/utils.ts
sed -i 's#^export const apiUrl.*#export const apiUrl = "REDACTED";#' $REPO_FOLDER/src/utils.ts
EDIT: Provided updated sed commands to modify utils.ts that work after overnight (2024-05-28) commits to pagefaultgames/pokerogue.
... and that is I think everything. Your setup will likely be wildly different than mine so I hope at least some of this craziness helps you on your journey that works for your setup.
daily rankings What to do if invalid
@fatmagic -- What kind of setup are you going for?
Hey @mjferrante83 - Thanks for the long reply! Sorry to make you write so much. I'm not using Docker at all. I setup on a standard Ubuntu 20 Headless VM - "pokerogue" and "rogueserver" on the same VM (same IP). So I'm trying to figure out how to make this work for a single-self-host Linux setup.
I have the game working... pokerogue and rogueserver work (afaik), and it's talking to the DB because it generated the tables and structure. But as I was asking in my original post/issue at the top, it's running in cookie mode. I just want it to switch to auth/account mode. You figured out how to do it for the containers/docker, but I'm not sure how to adapt that to an all inclusive single host VM.
Does that explain it better? Thank you for any help!
export VITE_BYPASS_LOGIN=-1
I think this is all you need. Pass this in your VM host OS and reload your game instance.
export VITE_BYPASS_LOGIN=-1I think this is all you need. Pass this in your VM host OS and reload your game instance.
Hey @mjferrante83 - OK this is very helpful. I just need a little direction on where to define the environment variable. I tried to define it at the system level (sudo nano /etc/environment), which I can see by entering "env" which lists all my system env variables. I have it listed there (and rebooted the server), but it's not pulling it into pokerogue. I'm assuming there is another location I need to define the variable, and pokerogue will pick it up.
I'm trying not to adjust or manually edit anything in the "pokerogue" directory so I can just "git pull" any updates without having to worry about manual edits. I'm not a programmer, so trying to do all of the things you did above to preserve your manual edits is not something I would be able to do easily. I would rather preserve the git exactly as it is, and just pass the variable.
I hope this makes sense.... again thank you SO much for the help so far. I'm so close!! :)
EDIT: I was fiddling around with the ".env" file in the "pokerogue" directory, and if I manually set "VITE_BYPASS_LOGIN=1" then I get the account login! Progress... but not sure how to get an external environment variable to pass in. It still isn't recognizing the system wide env variable.
EDIT: NEVERMIND that isn't working, it didn't give me an account login now. I don't know what I'm doing :(
@mjferrante83 OK I almost figured it out. I'm using PM2 to daemonize my Pokerogue launch. I had to pass the variable into PM2, which accepts it, and I get the Account creation/login consistently.
But I can't seem to register a new account. Anything I type into the Username and Password/Password Confirm just does the error sound, and isn't accepting it.
Does this mean the connection to the DB isn't working, and it's failing to create the account? Did you run into this problem?
Getting no answers here... so I will close this ticket for now, and open a new issue with not being able to create an account. Thanks for all the help everyone.