leanprover-community / lean4game

Server to host lean games.
https://adam.math.hhu.de
GNU General Public License v3.0
137 stars 25 forks source link

Fix Bug with Environment Variables for Ports #236

Closed RexWzh closed 1 month ago

RexWzh commented 1 month ago

Thanks for the awesome project! I'm working on deploying a game myself and encountered a bug related to port configuration. I've made a small change to fix it.

Description: This PR updates the Vite server configuration to allow the setting of the client port using the environment variable CLIENT_PORT, with a default value of 3000. Additionally, it fixes a bug related to the backendPort configuration.

The code here:

https://github.com/leanprover-community/lean4game/blob/4ed0753bb06b12437152a6e1ebf2b55774878fe8/vite.config.ts#L38

Can results in the following error:

❯ export PORT=8082
❯ npm run start

> lean4-game@0.1.0 start
> concurrently -n server,client -c blue,green "npm run start_server" "npm run start_client"

[server] 
[server] > lean4-game@0.1.0 start_server
[server] > (cd server && lake build) && (cd relay && cross-env NODE_ENV=development nodemon -e mjs --exec "node ./index.mjs")
...
[server] Listening on 8082
[client] (node:17273) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead.
[client] (Use `node --trace-deprecation ...` to show where the warning was created)
[client] 3:55:28 PM [vite] http proxy error at /i18n/g/local/NNG4/en/Game.json:
[client] Error: connect ECONNREFUSED 127.0.0.1:8080
[client]     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1606:16)
[client] 3:55:28 PM [vite] http proxy error at /data/g/local/NNG4/inventory.json:
[client] Error: connect ECONNREFUSED 127.0.0.1:8080
[client]     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1606:16)
...

Changes:

Benefits:

joneugster commented 1 month ago

LGTM, Thank you @RexWzh .

Is there a particular reason the env variables are called PORT and CLIENT_PORT, or could they be prefixed with e.g. LEAN4GAME_ in the future?

RexWzh commented 1 month ago

LGTM, Thank you @RexWzh .

Is there a particular reason the env variables are called PORT and CLIENT_PORT, or could they be prefixed with e.g. LEAN4GAME_ in the future?

Thanks for the reply ;)

The variable PORT is compatible with the code in index.mjs and npm_scripts.md

https://github.com/leanprover-community/lean4game/blob/b091ec579b13a7eaa7ef975b80091ceacd02c692/relay/index.mjs#L31

https://github.com/leanprover-community/lean4game/blob/b091ec579b13a7eaa7ef975b80091ceacd02c692/doc/npm_scripts.md?plain=1#L9

Considering the script in package.json:

"start_server": "(cd server && lake build) && (cd relay && cross-env NODE_ENV=development nodemon -e mjs --exec \"node ./index.mjs\")",
"start_client": "cross-env NODE_ENV=development vite --host",

It is appropriate to use names like SERVER_PORT or CLIENT_PORT.