Skip to content

Instantly share code, notes, and snippets.

@Nolkeg
Created July 3, 2025 12:05
Show Gist options
  • Save Nolkeg/0ce7b348bd79c8a2fab3b30fb9bf0cd0 to your computer and use it in GitHub Desktop.
Save Nolkeg/0ce7b348bd79c8a2fab3b30fb9bf0cd0 to your computer and use it in GitHub Desktop.
Python server to server webgl brotli build
import http.server
import socketserver
import os
PORT = 8000
class BrotliHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
if self.path.endswith(".br"):
self.send_header("Content-Encoding", "br")
if self.path.endswith(".js.br"):
self.send_header("Content-Type", "application/javascript")
elif self.path.endswith(".wasm.br"):
self.send_header("Content-Type", "application/wasm")
elif self.path.endswith(".data.br"):
self.send_header("Content-Type", "application/octet-stream")
super().end_headers()
def guess_type(self, path):
if path.endswith(".br"):
path = path[:-3]
return super().guess_type(path)
web_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(web_dir)
with socketserver.TCPServer(("", PORT), BrotliHTTPRequestHandler) as httpd:
print(f"Serving Unity WebGL Brotli build at http://localhost:{PORT}")
httpd.serve_forever()
@Nolkeg
Copy link
Author

Nolkeg commented Jul 3, 2025

how to

  1. place this file in the same directory as the index.html
  2. run python server.py
  3. open another terminal and run ngrok
  4. access the ngrok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment