added support for config file
This commit is contained in:
parent
108bafe299
commit
b3e8ff6ffb
|
@ -2,9 +2,17 @@
|
||||||
|
|
||||||
require '../vendor/autoload.php';
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
// read config
|
||||||
|
$configFile = dirname(__DIR__) . "/config.json";
|
||||||
|
$configJSON = file_get_contents($configFile);
|
||||||
|
$config = json_decode($configJSON, associative: true);
|
||||||
|
|
||||||
|
|
||||||
use App\Controller\DatabaseConnection;
|
use App\Controller\DatabaseConnection;
|
||||||
use App\Controller\RequestController;
|
use App\Controller\RequestController;
|
||||||
|
|
||||||
|
|
||||||
|
// TODO only valid clients?
|
||||||
header("Access-Control-Allow-Origin: *");
|
header("Access-Control-Allow-Origin: *");
|
||||||
header("Content-Type: application/json; charset=UTF-8");
|
header("Content-Type: application/json; charset=UTF-8");
|
||||||
header("Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE");
|
header("Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE");
|
||||||
|
@ -12,28 +20,23 @@ header("Access-Control-Max-Age: 3600");
|
||||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||||
|
|
||||||
|
|
||||||
$dbConnection = (new DatabaseConnection())->getConnection();
|
|
||||||
|
|
||||||
|
|
||||||
// TODO make a log class
|
// TODO make a log class
|
||||||
$oFile = fopen ('log.txt', 'a');
|
$oFile = fopen ('log.txt', 'a');
|
||||||
|
|
||||||
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||||
fputs($oFile, $uri);
|
fputs($oFile, $uri . PHP_EOL);
|
||||||
$uri = explode( '/', $uri );
|
fclose($oFile);
|
||||||
|
|
||||||
|
$uri = explode( '/', $uri );
|
||||||
if ($uri[1] !== 'api') {
|
if ($uri[1] !== 'api') {
|
||||||
header("HTTP/1.1 404 Not Found");
|
header("HTTP/1.1 404 Not Found");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO check for valid API key
|
|
||||||
|
|
||||||
$requestMethod = $_SERVER["REQUEST_METHOD"];
|
$requestMethod = $_SERVER["REQUEST_METHOD"];
|
||||||
|
$dbConnection = (new DatabaseConnection(config: $config))->getConnection();
|
||||||
|
|
||||||
// pass the request method and user ID to the PersonController and process the HTTP request:
|
|
||||||
$controller = new RequestController($dbConnection, $requestMethod, $uri);
|
$controller = new RequestController($dbConnection, $requestMethod, $uri);
|
||||||
$controller->processRequest();
|
$controller->processRequest();
|
||||||
|
|
||||||
|
|
||||||
fclose($oFile);
|
|
Loading…
Reference in New Issue