65 lines
2.7 KiB
PHP
65 lines
2.7 KiB
PHP
<?php
|
|
// ====================================================================
|
|
// 1. ENVIRONMENT CONFIGURATION & GLOBAL SETTINGS
|
|
// ====================================================================
|
|
// Set time zone and ensure clean error reporting for debugging development builds
|
|
date_default_timezone_set('UTC');
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 0); // Disabled in production builds so errors don't corrupt JSON payloads
|
|
|
|
// ====================================================================
|
|
// 2. DATABASE CONFIGURATION (Aiven Cloud Connection Matrix)
|
|
// ====================================================================
|
|
// Fall back to standard local development values if variables aren't injected by Vercel
|
|
$db_host = getenv('DB_HOST') ?: '127.0.0.1';
|
|
$db_port = getenv('DB_PORT') ?: '3306';
|
|
$db_user = getenv('DB_USER') ?: 'root';
|
|
$db_pass = getenv('DB_PASS') ?: '';
|
|
$db_name = 'defaultdb';
|
|
|
|
try {
|
|
// Open a secure database link using the PHP Data Objects (PDO) framework
|
|
$pdo = new PDO(
|
|
"mysql:host=$db_host;port=$db_port;dbname=$db_name;charset=utf8mb4",
|
|
$db_user,
|
|
$db_pass,
|
|
[
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
PDO::ATTR_EMULATE_PREPARES => false,
|
|
PDO::MYSQL_ATTR_SSL_CA => true, // Encapsulated correctly inside the array
|
|
]
|
|
);
|
|
} catch (PDOException $e) {
|
|
// If the database connection drops, immediately return a clean JSON error response
|
|
header('Content-Type: application/json');
|
|
http_response_code(500);
|
|
echo json_encode([
|
|
"error" => "Secure cloud database connection error.",
|
|
"status" => "fail"
|
|
]);
|
|
exit();
|
|
}
|
|
|
|
// ====================================================================
|
|
// 3. MEDIA UPLOAD & STORAGE CONFIGURATION (Cloudinary)
|
|
// ====================================================================
|
|
// Pull raw cloudinary:// URL string directly from Vercel's Environment Variables
|
|
$cloudinary_env = getenv('CLOUDINARY_URL') ?: 'cloudinary://LOCAL_MOCK_KEY_FOR_TESTING';
|
|
|
|
// Define it as a global constant so your existing media/upload scripts run unchanged
|
|
define('CLOUDINARY_URL', $cloudinary_env);
|
|
|
|
|
|
// ====================================================================
|
|
// 4. API UTILITY FUNCTIONS (Optional helper block for your endpoints)
|
|
// ====================================================================
|
|
/**
|
|
* Standardized function to echo clean JSON responses back to the Instagram app
|
|
*/
|
|
function sendJsonResponse($data, $status_code = 200) {
|
|
header('Content-Type: application/json');
|
|
http_response_code($status_code);
|
|
echo json_encode($data);
|
|
exit();
|
|
}
|