Files
islamicconfig/server.py
mstfyldz 52029d49ab docker
2026-03-06 20:10:48 +03:00

48 lines
2.0 KiB
Python
Raw Permalink 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):
if self.path == '/islamic.json':
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('islamic.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'))
elif self.path == '/':
self.send_response(200)
self.send_header('Content-Type', 'text/plain; charset=utf-8')
self.end_headers()
self.wfile.write(b"")
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()