Create database connection and add API route

This commit is contained in:
bye 2024-06-28 19:28:28 +01:00
parent 97cf3b02ac
commit 3fbcfa7159
2 changed files with 22 additions and 1 deletions

15
api.php Normal file
View File

@ -0,0 +1,15 @@
<?php
header('Content-Type: application/json');
$response = [
"response" => [
"success" => false,
"status_code" => 404
],
'body' => [
'message' => 'That endpoint could not be found.'
]
];
echo json_encode($response, JSON_PRETTY_PRINT);

View File

@ -8,7 +8,12 @@ try {
exit;
}
// TODO: Init PDO.
// Connect to database
try {
$pdo = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD, PDO_OPTIONS);
} catch (PDOException $e) {
echo "<b>Critical error:</b> " . $e->getMessage() . "<br />";
}
// Starts the session
// TODO: write this to use the database to work across more than one server
@ -29,6 +34,7 @@ if (str_ends_with($path, '/') && $path != '/') {
$routes = [
'' => function () { require 'views/home.php'; },
'api' => function () { require 'api.php'; /* Handoff further routing to API script. */ }
];
//print_r($path_array);