Update config.php
This commit is contained in:
parent
1d259a49a9
commit
9dbad9cd51
1 changed files with 58 additions and 55 deletions
119
config.php
119
config.php
|
|
@ -1,62 +1,65 @@
|
|||
<?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); // Keep disabled in production 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') ?: 'nostolgagram-nostolgagram.i.aivencloud.com';
|
||||
$db_port = getenv('DB_PORT') ?: '3306'; // Default MySQL port (Aiven will overwrite this with 23006 via Vercel)
|
||||
$db_user = getenv('DB_USER') ?: 'avnadmin';
|
||||
$db_pass = getenv('DB_PASS') ?: '';
|
||||
$db_name = 'defaultdb'; // Aiven's default workspace name
|
||||
|
||||
try {
|
||||
// Open a secure database link using the fast, modern 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,
|
||||
]
|
||||
);
|
||||
} catch (PDOException $e) {
|
||||
// If the database connection drops, immediately return a clean JSON error response
|
||||
// so the patched Instagram 6.20.2 client app doesn't crash or hang.
|
||||
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 your 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)
|
||||
// ====================================================================
|
||||
/**
|
||||
* NostolgaGram Configuration Hub v1.0
|
||||
* Architecture: InfinityFree Core Matrix + Cloudinary CDN Processing
|
||||
* Standardized function to echo clean JSON responses back to the Instagram app
|
||||
*/
|
||||
|
||||
// 1. Universal Security and Client Handshake Headers
|
||||
// Crucial for allowing old Android clients to connect without CORS errors
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, DELETE");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
|
||||
|
||||
// Handle preflight OPTIONS requests instantly before they reach feature files
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 2. Database Connectivity Profiles
|
||||
// Swap these placeholders with your actual keys from your InfinityFree Client Area
|
||||
define('DB_HOST', 'sql112.infinityfree.com');
|
||||
define('DB_USER', 'if0_42261255');
|
||||
define('DB_PASS', '8d1WbfEonq');
|
||||
define('DB_NAME', 'if0_42261255_nostolgagram');
|
||||
|
||||
// 3. Cloudinary Edge CDN Credentials
|
||||
// Swap with your actual cloud account name. The preset matches your unsigned configuration.
|
||||
define('CLOUDINARY_CLOUD_NAME', 'dnkm8pijh');
|
||||
define('CLOUDINARY_UPLOAD_PRESET', 'nostolgagram');
|
||||
|
||||
// 4. Global Managed Database Connection Gateway (PDO)
|
||||
// This function can be safely executed by any file in your directory tree.
|
||||
function getDB() {
|
||||
static $dbInstance = null;
|
||||
|
||||
// Reuse existing connection if already established during the request lifecycle
|
||||
if ($dbInstance !== null) {
|
||||
return $dbInstance;
|
||||
}
|
||||
|
||||
try {
|
||||
$dbInstance = new PDO(
|
||||
"mysql:host=" . DB_HOST . ";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,
|
||||
]
|
||||
);
|
||||
return $dbInstance;
|
||||
} catch (PDOException $e) {
|
||||
// Return structured JSON instead of raw PHP syntax blocks if the database drops
|
||||
http_response_code(500);
|
||||
die(json_encode([
|
||||
"status" => "fail",
|
||||
"message" => "Database node offline."
|
||||
]));
|
||||
}
|
||||
function sendJsonResponse($data, $status_code = 200) {
|
||||
header('Content-Type: application/json');
|
||||
http_response_code($status_code);
|
||||
echo json_encode($data);
|
||||
exit();
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue