Backend: - path_validator.py: PathValidator-Klasse für Pfad-Validierung - file_ops.py: read_file, write_file, directory_exists, file_exists - content_types.py: get_content_type mit EXTENSION_MAP - handler.py: Handler-Klasse mit do_GET/do_PUT, nutzt above modules - serve.py: Entry-Point (main, find_free_port), setzt Handler.validator/directory Frontend: - css/variables.css: CSS-Variablen (--bg-*, --text-*, --accent, etc.) - css/styles.css: Alle CSS-Regeln (modal, card, template-grid, etc.) - js/utils.js: esc, showToast, copyContentToClipboard - js/modal.js: showModal, closeModal, closeEditModal, wasViewModalOpen - js/editor.js: editModalContent, createJsonEditUI, extractJsonFromForm - js/api.js: viewTemplate, copyContent, loadTemplates, saveEditedContent - js/templates.js: renderTemplates, applyFilters, parseTypeFromHash - js/main.js: Event-Listener, Hash-Filter, Initialisierung - index.html: Inline-CSS/JS entfernt, <link>/<script src>-Tags hinzugefügt Smoke test: SO_REUSEADDR für schnelle Port-Wiederverwendung
65 lines
1.7 KiB
Python
Executable file
65 lines
1.7 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 find_free_port(start_port=9000):
|
|
"""Finde einen freien Port ab start_port.
|
|
|
|
Für zukünftige Smoke-Test-Integration.
|
|
"""
|
|
import socket
|
|
|
|
port = start_port
|
|
while port < 10000:
|
|
try:
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
s.bind(("", port))
|
|
return port
|
|
except OSError:
|
|
port += 1
|
|
return None
|
|
|
|
|
|
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()
|