Skip to content

Instantly share code, notes, and snippets.

@GabeBenjamin
Last active September 24, 2023 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GabeBenjamin/37da77ee3c63fe3434ceb6ecb7b73231 to your computer and use it in GitHub Desktop.
Save GabeBenjamin/37da77ee3c63fe3434ceb6ecb7b73231 to your computer and use it in GitHub Desktop.
Simple python server to run HTML5 Godot 4.0+ games locally
#!/usr/bin/env python3
"""
If you run into the errors for "Cross Origin Isolation" and
"SharedArrayBuffer" when trying to run your exported HTML Godot
game, use this simple server to fix the problem!
Create this file in the same folder as your exported HTML files
and run with `python ./server.py`. Then open a web browser
and go to localhost:8000
"""
from http.server import HTTPServer, SimpleHTTPRequestHandler, test
import sys
class CORSRequestHandler (SimpleHTTPRequestHandler):
def end_headers (self):
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
SimpleHTTPRequestHandler.end_headers(self)
if __name__ == '__main__':
test(CORSRequestHandler, HTTPServer, port=int(sys.argv[1]) if len(sys.argv) > 1 else 8000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment