<?php

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

// 2. Cek Path Folder Laravel
$laravelPath = __DIR__.'/../../laravel';

if (!file_exists($laravelPath.'/vendor/autoload.php')) {
    die("Error Fatal: Folder 'laravel' atau 'vendor' tidak ditemukan di $laravelPath. Pastikan posisi file sudah benar.");
}

/*
|--------------------------------------------------------------------------
| Load Framework
|--------------------------------------------------------------------------
*/
require $laravelPath.'/vendor/autoload.php';
$app = require_once $laravelPath.'/bootstrap/app.php';

$kernel = $app->make(Kernel::class);

try {
    $response = $kernel->handle(
        $request = Request::capture()
    );
    $response->send();
    $kernel->terminate($request, $response);
} catch (\Exception $e) {
    // Jika Laravel error, tampilkan detailnya di sini
    echo "<h1>Laravel Error:</h1>";
    echo "<p><strong>Pesan:</strong> " . $e->getMessage() . "</p>";
    echo "<p><strong>File:</strong> " . $e->getFile() . " baris " . $e->getLine() . "</p>";
    echo "<pre>" . $e->getTraceAsString() . "</pre>";
}