-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
40 lines (30 loc) · 1.04 KB
/
index.php
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
<?php
// Define global constant to prevent direct script loading
define('MY_APP', true);
// Load the routers responsible for handling API requests
require_once __DIR__ . "/config.php";
require_once __DIR__ . "/api/APIRouter.php";
require_once __DIR__ . "/frontend/FrontendRouter.php";
// Get URL path
// http://localhost/multitier-shop/[api/posts/5]
// http://localhost/multitier-shop/[home/posts] [PATH]
$path = $_GET["path"];
$path_parts = explode("/", $path);
$base_path = strtolower($path_parts[0]);
$query_params = $_GET;
// If the URL path starts with "api", load the API
if($base_path == "api"){
// Handle requests using the API router
$api = new APIRouter($path_parts, $query_params);
$api->handleRequest();
}
// If the URL path starts with "home", load the frontend
else if($base_path == "home"){
// Handle requests using the frontend router
$frontend = new FrontendRouter($path_parts, $query_params);
$frontend->handleRequest();
}
else{ // If URL path is not API, redirect to home
header('Location: home');
die();
}