<?php

declare(strict_types=1);

use GrowConnect\Core\Router;
use GrowConnect\Core\Session;

if (PHP_SAPI === 'cli-server') {
    $path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
    $file = __DIR__ . $path;
    if ($path !== '/' && is_file($file)) {
        return false;
    }
}

require dirname(__DIR__) . '/app/bootstrap.php';

if (!gc_is_installed()) {
    header('Location: install.php');
    exit;
}

gc_boot();
Session::start();

header('X-Frame-Options: SAMEORIGIN');
header('X-Content-Type-Options: nosniff');
header('Referrer-Policy: strict-origin-when-cross-origin');

$router = new Router();
require GC_ROOT . '/routes/web.php';
require GC_ROOT . '/routes/api.php';
$router->dispatch();
