<?php

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

// Determine if the application is in maintenance mode...
if (file_exists($maintenance = __DIR__ . '/../storage/framework/maintenance.php')) {
    require $maintenance;
}

$file = $_SERVER['REQUEST_URI'];
$storagePath = __DIR__ . '/..' . $file;
$publicPath = __DIR__ . '/public' . $file;
$storagePath = realpath($storagePath);
if (is_file($storagePath)) {
    // Serve file from storage/
    header('Content-Type: ' . mime_content_type($storagePath));
    readfile($storagePath);
    exit;
} elseif (is_file($publicPath)) {
    // Serve file from public/
    header('Content-Type: ' . mime_content_type($publicPath));
    readfile($publicPath);
    exit;
} 
// Register the Composer autoloader...
require __DIR__ . '/../vendor/autoload.php';

// Bootstrap Laravel and handle the request...
$app = require_once __DIR__ . '/../bootstrap/app.php';

$app->usePublicPath(__DIR__);

$kernel = $app->make(Kernel::class);

$response = $kernel->handle(
    $request = Request::capture()
)->send();

$kernel->terminate($request, $response);
