While trying to host my video game made with Godot 4 with Flask, I've ran into a problem-- the game doesn't load, and instead there is a spinning circle.
The error messages are as follows:
GET http://127.0.0.1:5000/game/index.worker.js net::ERR_BLOCKED_BY_RESPONSE 200 (OK)
(or 302 when not hard-reloading the page)
Unchecked runtime.lastError: The message port closed before a response was received.
and also a repeating set of errors:
index.js:14010 still waiting on run dependencies:
onPrintError @ index.js:14010
(anonymous) @ index.js:737
setInterval (async)
addRunDependency @ index.js:727
createWasm @ index.js:886
(anonymous) @ index.js:12933
(anonymous) @ index.js:14253
Promise.then (async)
(anonymous) @ index.js:14251
doInit @ index.js:14250
init @ index.js:14267
startGame @ index.js:14366
(anonymous) @ (index):224
(anonymous) @ (index):244
index.js:14010 dependency: wasm-instantiate
onPrintError @ index.js:14010
(anonymous) @ index.js:739
setInterval (async)
addRunDependency @ index.js:727
createWasm @ index.js:886
(anonymous) @ index.js:12933
(anonymous) @ index.js:14253
Promise.then (async)
(anonymous) @ index.js:14251
doInit @ index.js:14250
init @ index.js:14267
startGame @ index.js:14366
(anonymous) @ (index):224
(anonymous) @ (index):244
index.js:14010 (end of list)
The output from Flask looks like this:
127.0.0.1 - - [22/Jun/2023 09:37:40] "GET /game/index.FILE.EXTENSION HTTP/1.1" 200 -
where FILE and EXTENSION are exactly what they sound like.
The code for the website is as follows:
from flask import Flask, send_from_directory
app = Flask(__name__)
@app.route('/<game>/')
def index(game):
response = send_from_directory(f'./{ game }', 'index.html')
response.headers.add('Cross-Origin-Opener-Policy', 'same-origin')
response.headers.add('Cross-Origin-Embedder-Policy', 'require-corp')
return response
@app.route('/<game>/<file>')
def game(game, file):
return send_from_directory(f'./{ game }', file)
app.run()
and the filesystem looks like this:
(it was exported as index.html, but is the same with a proper name)
Also, when just opening up the file as a static website, it just states that it needs Cross Origin Isolation, so I can't test it there. The build does run fine on itch.io
The Unchecked runtime.lastError
message was caused by an extension according to this, so I opened up a different browser without extensions, and that was gone! The others were still there, and I can't find anything on how to fix this.
Turns out that I needed to enable Cross Origin Isolation on the other files aswell, and now it is working fine.