Files
islamicconfig/server.py
mstfyldz 18a96a0154 docker
2026-03-06 20:05:14 +03:00

44 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
# Kök dizin (/) veya /config.json isteklerinde JSON dönüyoruz
if self.path in ['/', '/config.json', '/api']:
self.send_response(200)
self.send_header('Content-Type', 'application/json; charset=utf-8')
# CORS ayarları (Uygulamalardan sorunsuz erişim için)
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET, OPTIONS')
self.send_header('Access-Control-Allow-Headers', 'Content-Type')
self.end_headers()
try:
with open('config.json', 'r', encoding='utf-8') as f:
content = f.read()
self.wfile.write(content.encode('utf-8'))
except Exception as e:
error_res = json.dumps({"error": "Config file not found or readable.", "details": str(e)})
self.wfile.write(error_res.encode('utf-8'))
else:
self.send_response(404)
self.send_header('Content-Type', 'application/json; charset=utf-8')
self.end_headers()
self.wfile.write(json.dumps({"error": "Endpoint Not Found"}).encode('utf-8'))
def do_OPTIONS(self):
# CORS preflight isteklerine yanıt ver
self.send_response(200)
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET, OPTIONS')
self.send_header('Access-Control-Allow-Headers', 'Content-Type')
self.end_headers()
if __name__ == '__main__':
# Coolify port ayarı (Varsayılan 80)
port = int(os.environ.get('PORT', 80))
server = HTTPServer(('0.0.0.0', port), RequestHandler)
print(f"Sunucu 0.0.0.0:{port} adresinde çalışıyor...")
server.serve_forever()