import http.server
import ssl
import os

PORT = 8443

# Cambia directory se necessario (opzionale)
# os.chdir('/percorso/della/tua/cartella')

server_address = ('0.0.0.0', PORT)
handler = http.server.SimpleHTTPRequestHandler

# Aggiungi il supporto per i file .wasm o .glb se necessario
handler.extensions_map.update({
    '.webapp': 'text/cache-manifest',
    '.json': 'application/json',
    '.glb': 'model/gltf-binary',
    '.wasm': 'application/wasm',
})

httpd = http.server.HTTPServer(server_address, handler)

# Configura SSL
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain(certfile="cert.pem", keyfile="key.pem")
httpd.socket = context.wrap_socket(httpd.socket, server_side=True)

print(f"Server HTTPS avviato su port {PORT}")
print(f"Indirizzo locale: https://localhost:{PORT}")
# Comando per mostrare l'IP di Linux nel terminale
os.system("hostname -I | awk '{print \"Indirizzo remoto: https://\" $1 \":" + str(PORT) + "\"}'")

httpd.serve_forever()
