pygame-web / pygbag

python and pygame wasm for everyone ( packager + test server + simulator )
https://github.com/pygame-web
MIT License
295 stars 34 forks source link

ERROR 404 when GET /repo/index.json from self-hosting CDN #128

Closed Newverse-Wiki closed 9 months ago

Newverse-Wiki commented 9 months ago

I upload archives/ to my website server for better internet connections. The structure of archives/ on my server is like this:

archives ├─ 0.8/ ├─ README.md ├─ favicon.ico ├─ repo/ └─ server.py

The URL of archives/ on my server is like this: https://www.example.com/games/archives/

When running pygbag, I specify the CDN with --cdn https://www.example.com/games/archives/0.8/

When GET the resources from CDN, files in archives/0.8/ are available

"GET //games/archives/0.8/python311/main.data HTTP/1.1" 200 - "GET //games/archives/0.8/pythonrc.py HTTP/1.1" 200 -

but files in archives/repo/ got a wrong URL

ERROR 404: https://www.example.com/archives/repo/index-bi.json code 404, message File not found "GET /archives/repo/index-bi.json HTTP/1.1" 404 -

It seems that when GET files in repo/ the logic is not like "cd ../repo"

So, must I put the archives/ in the root / of my website, like https://www.examples.com/archives/ Or any config options to specify where to Get files in repo/?

pmp-p commented 9 months ago

"repo" is only a temporary setup to host wheel until pypi sorted out the WebAssembly wheel distribution problem. Don't spend too much time on that it can change anytime (and will).

In the near future importing a module will require main.py to support any one of those

https://peps.python.org/pep-0722/

https://peps.python.org/pep-0723/

on my local setup i do that:

user@pp /data/git $ file pygbag archives showroom
pygbag:   directory
archives: directory
showroom: directory
user@pp /data/git $ python3 archives/server.py 
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

that one start a normal webserver on port 8000 and keep running

pygbag --dev --template default.tmpl main.py

the second switch pygbag to port 8666 and fetch repo+wheels from archives/repo folder on http://localhost:8000 instead of internet you may have to put 0.8 files in pygbag/0.0/ if not using a full pygbag git build.

Newverse-Wiki commented 9 months ago

Thanks for your prompt and detailed reply.

I start and keep running the CDN server on my website server by python3 archives/server.py and proxy http://localhost:8000 -> https://games.example.com on server.

On local, I pack the game by pygbag --cdn https://games.example.com/archives/0.8/ game_folder I check the logs of both remote CDN server and local game server, everything is going well and the game runs just fine.

I write these in case anyone might wish to self-host CDN server for archives/

Thanks a lot for your efforts on pygbag, wonderful job!