Skip to content

Commit

Permalink
disallow directory listing and default to index.html via witchery
Browse files Browse the repository at this point in the history
  • Loading branch information
grymmy committed Dec 9, 2024
1 parent ccff7a6 commit 3663662
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions serve.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
#!/usr/bin/env python3
from http import server # Python 3
from http import server # Python 3
import os


class MyHTTPRequestHandler(server.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
server.SimpleHTTPRequestHandler.end_headers(self)
def do_GET(self):
if self.path == '/':
self.path = "index.html"
return server.SimpleHTTPRequestHandler.do_GET(self)

def end_headers(self):
self.send_my_headers()
server.SimpleHTTPRequestHandler.end_headers(self)

def send_my_headers(self):
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
self.send_header("Cross-Origin-Opener-Policy", "same-origin")

def send_my_headers(self):
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
self.send_header("Cross-Origin-Opener-Policy", "same-origin")

if __name__ == '__main__':
server.test(HandlerClass=MyHTTPRequestHandler, port=os.environ.get('PORT', 8080))
server.test(HandlerClass=MyHTTPRequestHandler, port=os.environ.get('PORT', 8080))

0 comments on commit 3663662

Please sign in to comment.