This commit is contained in:
mstfyldz
2026-03-06 20:05:14 +03:00
parent e9b4daeeaf
commit 18a96a0154
2 changed files with 49 additions and 7 deletions

View File

@@ -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ı
# 80 portunu dışarı (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"]
# Kendi yazdığımız hafif Python sunucusunu çalıştır
CMD ["python", "server.py"]

43
server.py Normal file
View File

@@ -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()