fix : dockerfile
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
// ========================================
|
||||
// FILE: php/koneksi.php
|
||||
// Konfigurasi Koneksi Database
|
||||
// ========================================
|
||||
|
||||
// CORS HEADERS - Wajib ada agar request dari browser tidak diblok
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
||||
header('Access-Control-Allow-Headers: Content-Type, X-Requested-With');
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
// Handle preflight request (OPTIONS)
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Baca dari Environment Variable (untuk deployment Coolify/server)
|
||||
// Jika tidak ada, fallback ke konfigurasi XAMPP lokal
|
||||
$host = getenv('DB_HOST') ?: "localhost";
|
||||
$username = getenv('DB_USER') ?: "root";
|
||||
$password = getenv('DB_PASSWORD') ?: "";
|
||||
$database = getenv('DB_DATABASE') ?: "pemetaan_kemiskinan";
|
||||
$port = getenv('DB_PORT') ?: 3306;
|
||||
|
||||
// KONEKSI MYSQLI
|
||||
$conn = new mysqli($host, $username, $password, $database, (int)$port);
|
||||
|
||||
// CEK KONEKSI
|
||||
if ($conn->connect_error) {
|
||||
sendJSON('error', 'Koneksi database gagal: ' . $conn->connect_error);
|
||||
exit();
|
||||
}
|
||||
|
||||
// SET CHARSET UTF-8
|
||||
$conn->set_charset("utf8mb4");
|
||||
|
||||
// FUNCTION UNTUK ESCAPE INPUT
|
||||
function sanitize($string, $conn) {
|
||||
return $conn->real_escape_string(strip_tags(trim($string)));
|
||||
}
|
||||
|
||||
// FUNCTION UNTUK RESPONSE JSON
|
||||
function sendJSON($status, $message, $data = null) {
|
||||
$response = [
|
||||
'status' => $status,
|
||||
'message' => $message
|
||||
];
|
||||
if ($data !== null) {
|
||||
$response['data'] = $data;
|
||||
}
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit();
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user