#!/usr/bin/env python3 # encoding: utf-8 """Use instead of `python3 -m http.server` when you need CORS and SharedArrayBuffer""" from http.server import HTTPServer, SimpleHTTPRequestHandler import sys class CORSRequestHandler(SimpleHTTPRequestHandler): def end_headers(self): self.send_header('Access-Control-Allow-Origin', '*') self.send_header('Cross-Origin-Opener-Policy', 'same-origin') self.send_header('Cross-Origin-Embedder-Policy', 'require-corp') self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate') return super(CORSRequestHandler, self).end_headers() port = 8003 if len(sys.argv) > 1: port = int(sys.argv[1]) httpd = HTTPServer(('', port), CORSRequestHandler) httpd.serve_forever()