24 lines
771 B
Python
24 lines
771 B
Python
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
import os
|
|
|
|
class CORSRequestHandler(SimpleHTTPRequestHandler):
|
|
def end_headers(self):
|
|
self.send_header('Cross-Origin-Embedder-Policy', 'require-corp')
|
|
self.send_header('Cross-Origin-Opener-Policy', 'same-origin')
|
|
super().end_headers()
|
|
|
|
def do_GET(self):
|
|
# Serve index.html for root path
|
|
if self.path == '/':
|
|
self.path = '/index.html'
|
|
return SimpleHTTPRequestHandler.do_GET(self)
|
|
|
|
# Change to the directory containing your files
|
|
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
# Run server
|
|
port = 8000
|
|
print(f"Starting server at http://localhost:{port}")
|
|
httpd = HTTPServer(('localhost', port), CORSRequestHandler)
|
|
httpd.serve_forever()
|