-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
44 lines (37 loc) · 1.14 KB
/
index.php
File metadata and controls
44 lines (37 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
require_once __DIR__ . '/vendor/autoload.php';
use FlowPHP\routes\Web;
use FlowPHP\routes\Api;
use FlowPHP\config\Database;
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();
// config access static files
$requestUri = $_SERVER['REQUEST_URI'];
if (preg_match('#^/public/(.+)$#', $requestUri, $matches)) {
$filePath = __DIR__ . '/public/' . $matches[1];
if (file_exists($filePath) && is_file($filePath)) {
$mimeType = mime_content_type($filePath);
header('Content-Type: ' . $mimeType);
readfile($filePath);
exit;
} else {
http_response_code(404);
echo "File not found.";
exit;
}
}
try {
$db = new Database();
$pdo = $db->getConnection();
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
if (preg_match('#^/api(/|$)#', $uri)) {
$api_router = new Api($pdo);
$api_router->handleRequest();
} else {
$web_router = new Web($pdo);
$web_router->handleRequest();
}
} catch (Exception $e) {
throw new \Exception('Internal Server Error: ' . $e->getMessage(), 500);
}