glitchcraft/server.py
Ole-Morten Duesund 4e58281d51 Rebrand to GlitchCraft with IPv6 support
Changes:
- Renamed from "Text Corruptor" to "GlitchCraft"
- New slogan: "Artisanal text corruption, served fresh!"
- Updated server to support both IPv4 and IPv6 (dual-stack)
- Server now listens on all interfaces (::) instead of just localhost
- Updated all references in code and documentation

The new name reflects both the glitch aesthetic and the craftsmanship
of creating beautifully corrupted text, with a playful tone.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-18 20:03:51 +02:00

61 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""
Simple HTTP server for testing the GlitchCraft PWA
Run with: python3 server.py
Then open http://localhost:8000/ in your browser
"""
import http.server
import socketserver
import socket
import os
PORT = 8000
# Serve from the app directory
DIRECTORY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "app")
class DualStackServer(socketserver.TCPServer):
"""TCP server that supports both IPv4 and IPv6."""
address_family = socket.AF_INET6
def __init__(self, *args, **kwargs):
# Disable dual stack to make it work on all systems
# Some systems have it enabled by default, some don't
super().__init__(*args, **kwargs)
# Enable dual stack - listen on both IPv4 and IPv6
self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
"""Custom HTTP request handler for serving the GlitchCraft PWA."""
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=DIRECTORY, **kwargs)
def end_headers(self):
# Add headers for PWA and CORS
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
self.send_header("Service-Worker-Allowed", "/")
self.send_header("X-Content-Type-Options", "nosniff")
super().end_headers()
if __name__ == "__main__":
# Listen on all interfaces (:: for IPv6, which also handles IPv4 with dual stack)
HOST = "::" # Listen on all interfaces (IPv6 and IPv4)
with DualStackServer((HOST, PORT), MyHTTPRequestHandler) as httpd:
print(f"Server running on all interfaces at port {PORT}")
print(f"Access at:")
print(f" http://localhost:{PORT}/")
print(f" http://127.0.0.1:{PORT}/ (IPv4)")
print(f" http://[::1]:{PORT}/ (IPv6)")
print(f" http://<your-ip>:{PORT}/")
print(f"Serving files from: {DIRECTORY}")
print("Press Ctrl+C to stop the server")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nServer stopped.")