diff --git a/dockerfile b/dockerfile index a33aab6..0a75880 100644 --- a/dockerfile +++ b/dockerfile @@ -1,15 +1,14 @@ # En küçük Python imajını kullanıyoruz FROM python:3.11-alpine -# Çalışma dizinini ayarla (Burası senin "aynı klasör" dediğin yer) +# Çalışma dizinini ayarla WORKDIR /app -# Sadece JSON dosyanı kopyala -COPY config.json . +# JSON dosyasını ve Python sunucusu betiğini kopyala +COPY config.json server.py ./ -# 80 portunu dışarı aç +# 80 portunu dışarı aç (Coolify varsayılanı) EXPOSE 80 -# Python'un yerleşik HTTP sunucusunu 80 portunda çalıştır -# Bu komut direkt olarak klasördeki dosyaları servis eder -CMD ["python", "-m", "http.server", "80"] \ No newline at end of file +# Kendi yazdığımız hafif Python sunucusunu çalıştır +CMD ["python", "server.py"] \ No newline at end of file diff --git a/server.py b/server.py new file mode 100644 index 0000000..aeef6b5 --- /dev/null +++ b/server.py @@ -0,0 +1,43 @@ +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()