60 lines
2.0 KiB
PHP
Executable File
60 lines
2.0 KiB
PHP
Executable File
<?php
|
|
// Load environment variables from .env file
|
|
require_once realpath(__DIR__ . '/../vendor/autoload.php');
|
|
require_once 'load_env.php';
|
|
$env_file = '/home/intaleq-wallet/env/.env';
|
|
loadEnvironment($env_file);
|
|
|
|
// Get environment variables (You don't need user/pass for JWT auth itself)
|
|
$secretKey = getenv('SECRET_KEY'); // Only need the secret key now
|
|
|
|
// --- CORS Headers ---
|
|
$allowedOrigins = [
|
|
'https://walletintaleq.intaleq.xyz',
|
|
'https://wallet.siromove.com',
|
|
'https://wallet-syria.siromove.com',
|
|
'https://wallet-egypt.siromove.com',
|
|
'https://wallet-jordan.siromove.com',
|
|
];
|
|
$origin = $_SERVER['HTTP_ORIGIN'] ?? '';
|
|
if (in_array($origin, $allowedOrigins)) {
|
|
header("Access-Control-Allow-Origin: $origin");
|
|
} else {
|
|
header("Access-Control-Allow-Origin: https://walletintaleq.intaleq.xyz");
|
|
}
|
|
header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); // Adjust as needed
|
|
header("Access-Control-Allow-Headers: Content-Type, Authorization");
|
|
header('Content-Type: application/json'); // Set content type to JSON
|
|
|
|
// Handle preflight requests (OPTIONS)
|
|
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
|
http_response_code(200);
|
|
exit;
|
|
}
|
|
$dbname = getenv('dbname');
|
|
// --- Database Connection (Still needed for your application logic) ---
|
|
try {
|
|
$dsn = "mysql:host=localhost;dbname=$dbname;charset=utf8mb4";
|
|
$options = [
|
|
PDO::ATTR_EMULATE_PREPARES => false,
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8"
|
|
];
|
|
$user = getenv('USER'); // Still used for DB connection
|
|
$pass = getenv('PASS'); // Still used for DB connection
|
|
$con = new PDO($dsn, $user, $pass, $options);
|
|
|
|
// --- JWT Authentication ---
|
|
include "functions.php"; // Include the functions file
|
|
|
|
|
|
|
|
|
|
} catch (PDOException $e) {
|
|
error_log($e->getMessage());
|
|
http_response_code(500); // Internal Server Error
|
|
echo json_encode(['error' => 'A database error occurred.']);
|
|
exit;
|
|
}
|
|
?>
|