Skip to content
Snippets Groups Projects
Commit 3fbcfa71 authored by Bye's avatar Bye
Browse files

Create database connection and add API route

parent 97cf3b02
Branches
No related tags found
1 merge request!4Draft: Merge rewrite branch into main
api.php 0 → 100644
<?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);
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment