47 lines
1.3 KiB
Python
Executable file
47 lines
1.3 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
"""
|
|
Minimaler Entwicklungs-Server für die Prompt Templates Webansicht.
|
|
|
|
Startet auf Port 8081 und dient die statischen Dateien aus.
|
|
Nutzt modulare Handler und Pfad-Validierung.
|
|
"""
|
|
|
|
import logging
|
|
import os
|
|
import socketserver
|
|
|
|
# Support für direkte Ausführung (python3 web/serve.py) und Package-Import
|
|
try:
|
|
from .path_validator import PathValidator
|
|
from .handler import Handler
|
|
except ImportError:
|
|
from path_validator import PathValidator
|
|
from handler import Handler
|
|
|
|
# Verzeichnisse bestimmen
|
|
DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
|
ROOT_DIR = os.path.abspath(os.path.join(DIRECTORY, ".."))
|
|
|
|
# Validator initialisieren
|
|
validator = PathValidator(ROOT_DIR, DIRECTORY)
|
|
Handler.validator = validator
|
|
Handler.directory = DIRECTORY
|
|
|
|
|
|
def main():
|
|
PORT = 8081
|
|
logging.info("Serving on http://localhost:%s", PORT)
|
|
|
|
socketserver.TCPServer.allow_reuse_address = True
|
|
with socketserver.TCPServer(("", PORT), Handler) as httpd:
|
|
logging.info("Serving Prompt Templates on http://localhost:%s", PORT)
|
|
logging.info("Press Ctrl+C to stop")
|
|
logging.info("Directory: %s", DIRECTORY)
|
|
try:
|
|
httpd.serve_forever()
|
|
except KeyboardInterrupt:
|
|
logging.info("\nServer stopped")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|