#!/usr/bin/env python3
import http.server
import socketserver
import os

PORT = 9000
DIRECTORY = "/opt/data"

class MyHandler(http.server.SimpleHTTPRequestHandler):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, directory=DIRECTORY, **kwargs)
    
    def do_GET(self):
        if self.path == '/' or self.path == '/chat.html' or self.path == '/custom_chat_ui.html':
            self.path = '/custom_chat_ui.html'
        return super().do_GET()
    
    def log_message(self, format, *args):
        print("%s - - [%s] %s\n" % (self.address_string(), self.log_date_time_string(), format%args))

socketserver.TCPServer.allow_reuse_address = True

with socketserver.TCPServer(("", PORT), MyHandler) as httpd:
    print(f"✅ Server running at http://0.0.0.0:{PORT}/")
    print(f"✅ Open this URL in your browser: http://72.61.215.6:{PORT}/")
    print(f"✅ Direct link: http://72.61.215.6:{PORT}/custom_chat_ui.html")
    print("Press Ctrl+C to stop")
    httpd.serve_forever()
