ijsbreker/server.py
Frank Meeuwsen 7b181a5f12 feat: Sessie IJsbreker - interactief workshop spel
Browser-based interactief spel voor workshops waarbij deelnemers fysiek
kiezen tussen twee stellingen die op een beamer worden getoond.

Features:
- Presentatie modus met visuele timer rondom scherm
- Timer animatie loopt synchroon rond in opgegeven tijd
- Geluidssignaal bij einde timer
- Overlay met stellingen na timer (grayed out)
- Keyboard shortcuts (spatiebalk voor volgende)
- Direct eindscherm bij laatste stelling

- Web-based stellingen editor
- Flask backend voor config management
- Real-time CRUD operaties op stellingen
- Kleurenpicker voor achtergronden
- Validatie en filtering van lege stellingen
- Volledig offline werkend

Tech stack:
- Frontend: Pure HTML/CSS/JavaScript
- Backend: Python Flask + flask-cors
- Config driven via JSON

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 16:23:11 +01:00

67 lines
2 KiB
Python

#!/usr/bin/env python3
"""
Flask server voor IJsbreker spel
Serveert statische bestanden en biedt API endpoints voor config management
"""
from flask import Flask, send_from_directory, request, jsonify
from flask_cors import CORS
import json
import os
app = Flask(__name__)
CORS(app) # Enable CORS voor alle routes
CONFIG_FILE = 'config.json'
# Serve static files
@app.route('/')
def serve_index():
return send_from_directory('.', 'index.html')
@app.route('/<path:path>')
def serve_static(path):
if os.path.exists(path):
return send_from_directory('.', path)
return "File not found", 404
# API endpoint om config te laden
@app.route('/api/config', methods=['GET'])
def get_config():
try:
with open(CONFIG_FILE, 'r', encoding='utf-8') as f:
config = json.load(f)
return jsonify(config)
except Exception as e:
return jsonify({'error': str(e)}), 500
# API endpoint om config op te slaan
@app.route('/api/save-config', methods=['POST'])
def save_config():
try:
data = request.json
# Validatie: check of stellingen array bestaat
if 'stellingen' not in data:
return jsonify({'error': 'Geen stellingen gevonden'}), 400
# Filter lege stellingen eruit
data['stellingen'] = [
s for s in data['stellingen']
if s.get('links', '').strip() or s.get('rechts', '').strip()
]
# Schrijf naar config.json met mooie formatting
with open(CONFIG_FILE, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
return jsonify({'success': True, 'message': 'Config opgeslagen!'})
except Exception as e:
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
print("🎯 IJsbreker Server gestart!")
print("📝 Editor: http://localhost:8000/editor.html")
print("🎮 Spel: http://localhost:8000/")
print("\nDruk Ctrl+C om te stoppen")
app.run(debug=True, host='0.0.0.0', port=8000)