From 9c5f6f7e6df97d5d5d9407cb6165c63bc7460288 Mon Sep 17 00:00:00 2001 From: sundowndev Date: Sun, 5 Aug 2018 00:50:40 +0200 Subject: [PATCH] [Fix:#9] Server timezone --- server/app/routes.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/server/app/routes.php b/server/app/routes.php index 75dfa99..2b5ce78 100644 --- a/server/app/routes.php +++ b/server/app/routes.php @@ -6,6 +6,8 @@ use App\Service\JsonResponse; $router->setNamespace('\App\Controller'); $router->before('GET|POST|PUT|DELETE', '/.*', function () use ($router) { + date_default_timezone_set('Europe/Paris'); + # This will be always executed $dotEnvParser = new DotEnvParser(); $dotEnvParser->run(); @@ -15,19 +17,12 @@ $router->before('GET|POST|PUT|DELETE', '/.*', function () use ($router) { if ($_SERVER['HTTP_ACCEPT'] !== 'application/json') { $code = 400; $message = 'Accept header is not set to "application/json".'; - print $jsonResponse->create($code, $message, []); - exit(); + return $jsonResponse->create($code, $message, []); } elseif ($_SERVER['REQUEST_METHOD'] != 'GET' && $_SERVER['CONTENT_TYPE'] !== 'application/json') { $code = 400; $message = 'Content-type header is not set to "application/json".'; - print $jsonResponse->create($code, $message, []); - exit(); - }/* elseif ($_SERVER['HTTP_ORIGIN'] !== getenv('ALLOW_ORIGIN')) { - $code = 403; - $message = 'Unallowed origin.'; - print $jsonResponse->create($code, $message, []); - exit(); - }*/ + return $jsonResponse->create($code, $message, []); + } }); /** @@ -77,4 +72,7 @@ $router->mount('/users', function () use ($router) { // Get one task's tasks $router->get('/(\d+)/tasks', 'UserController@getTasks'); -}); \ No newline at end of file +}); + +// Quickfix for Chrome prelight request on OPTIONS method +$router->options('(.*)', 'DefaultController@index'); \ No newline at end of file