-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
40 lines (27 loc) · 899 Bytes
/
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
use Util\Json;
use Util\Routes;
use Service\ProductService;
require_once 'config.php';
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET,DELETE,POST,OPTIONS");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type");
exit;
}
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
try {
$routes = new Routes();
$productService = new ProductService($routes->getRoutes());
$response = $productService->handleRequest();
$json = new Json();
$json->processArrayToReturn($response);
} catch (Exception $exception) {
echo json_encode([
'Type' => 'ERROR',
'Response' => $exception->getMessage()
], JSON_THROW_ON_ERROR, 512);
exit;
}