404 on missing file

This commit is contained in:
tesseractcat 2022-08-25 01:25:22 -04:00
parent ab131cb55e
commit 72a9d75330

View File

@ -9,17 +9,20 @@ model = T2I()
class DreamServer(BaseHTTPRequestHandler): class DreamServer(BaseHTTPRequestHandler):
def do_GET(self): def do_GET(self):
self.send_response(200)
if self.path == "/": if self.path == "/":
self.send_response(200)
self.send_header("Content-type", "text/html") self.send_header("Content-type", "text/html")
self.end_headers() self.end_headers()
with open("./scripts/static/index.html", "rb") as content: with open("./scripts/static/index.html", "rb") as content:
self.wfile.write(content.read()) self.wfile.write(content.read())
else: elif os.path.exists("." + self.path):
self.send_response(200)
self.send_header("Content-type", "image/png") self.send_header("Content-type", "image/png")
self.end_headers() self.end_headers()
with open("." + self.path, "rb") as content: with open("." + self.path, "rb") as content:
self.wfile.write(content.read()) self.wfile.write(content.read())
else:
self.send_response(404)
def do_POST(self): def do_POST(self):
self.send_response(200) self.send_response(200)