Skip to content

Instantly share code, notes, and snippets.

@stevenanthonyrevo
Created October 21, 2021 05:10
Show Gist options
  • Select an option

  • Save stevenanthonyrevo/90e02210f72d876c78ffbca7db0e37d7 to your computer and use it in GitHub Desktop.

Select an option

Save stevenanthonyrevo/90e02210f72d876c78ffbca7db0e37d7 to your computer and use it in GitHub Desktop.
wasm_server - built in python3 supports, content-Type "application/wasm"
from http.server import BaseHTTPRequestHandler, HTTPServer
class HTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Cache-Control", "no-cache")
if self.path.endswith(".wasm"):
self.send_header("Content-Type", "application/wasm")
else:
self.send_header("Content-Type", "text/html")
self.end_headers()
urlpath = self.path
if urlpath == "/":
urlpath = "/index.html"
with open(f".{urlpath}", "rb") as f:
content = f.read()
self.wfile.write(content)
def main():
print("starting wasm server...")
server_address = ("localhost", 8080)
httpd = HTTPServer(server_address, HTTPRequestHandler)
print("running wasm server...")
httpd.serve_forever()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment