-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
58 lines (50 loc) · 2.27 KB
/
index.php
File metadata and controls
58 lines (50 loc) · 2.27 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
header('Content-type: application/json; charset=utf-8');
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
http_response_code(200);
exit(0);
}
$root_dir = __DIR__;
$handlers_dir = $root_dir."/handlers";
$functions_dir = $root_dir."/functions";
$db_con_file = $root_dir."/mysql/db_conn.php";
require($db_con_file);
if (substr($_SERVER['REQUEST_URI'], 0, 6) == '/notes') {
$notePath = substr($_SERVER['REQUEST_URI'], 6);
if ($notePath) {
if ($notePath[0] == "/") {
if (substr($notePath, 1)) {
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
require($handlers_dir."/getNoteById.php");
} elseif ($_SERVER['REQUEST_METHOD'] == 'PUT') {
require($handlers_dir."/editNoteById.php");
} elseif ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
require($handlers_dir."/deleteNoteById.php");
}
} elseif ($_SERVER['REQUEST_METHOD'] == 'GET') {
require($handlers_dir."/getAllNotes.php");
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
require($handlers_dir."/addNote.php");;
}
} else {
http_response_code(404);
$response = array("statusCode" => http_response_code(), "error" => "Not Found", "message" => "Not Found");
echo json_encode($response);
}
} elseif ($_SERVER['REQUEST_METHOD'] == 'GET') {
require($handlers_dir."/getAllNotes.php");
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
require($handlers_dir."/addNote.php");
} else {
http_response_code(404);
$response = array("statusCode" => http_response_code(), "error" => "Not Found", "message" => "Not Found");
echo json_encode($response);
}
} else {
http_response_code(404);
$response = array("statusCode" => http_response_code(), "error" => "Not Found", "message" => "Not Found");
echo json_encode($response);
}
$db_con->close();
?>