diff --git a/flextype/api/delivery/entries.php b/flextype/api/delivery/entries.php index d2f32ba6..3a211ef3 100644 --- a/flextype/api/delivery/entries.php +++ b/flextype/api/delivery/entries.php @@ -57,15 +57,23 @@ $app->get('/api/delivery/entries', function (Request $request, Response $respons Filesystem::write($delivery_entries_token_file_path, $flextype['parser']->encode(array_replace_recursive($delivery_entries_token_file_data, ['calls' => $delivery_entries_token_file_data['calls'] + 1]), 'yaml')); // Return response - return $response->withJson($data, $response_code); + return $response + ->withJson($data, $response_code) + ->withHeader('Access-Control-Allow-Origin', '*'); } } else { - return $response->withJson(["detail" => "Incorrect authentication credentials."], 401); + return $response + ->withJson(["detail" => "Incorrect authentication credentials."], 401) + ->withHeader('Access-Control-Allow-Origin', '*'); } } else { - return $response->withJson(["detail" => "Incorrect authentication credentials."], 401); + return $response + ->withJson(["detail" => "Incorrect authentication credentials."], 401) + ->withHeader('Access-Control-Allow-Origin', '*'); } } else { - return $response->withJson(["detail" => "Incorrect authentication credentials."], 401); + return $response + ->withJson(["detail" => "Incorrect authentication credentials."], 401) + ->withHeader('Access-Control-Allow-Origin', '*'); } }); diff --git a/flextype/api/delivery/images.php b/flextype/api/delivery/images.php index 33fa46e6..78e786f6 100644 --- a/flextype/api/delivery/images.php +++ b/flextype/api/delivery/images.php @@ -48,20 +48,31 @@ $app->get('/api/delivery/images/{path:.+}', function (Request $request, Response Filesystem::write($delivery_images_token_file_path, $flextype['parser']->encode(array_replace_recursive($delivery_images_token_file_data, ['calls' => $delivery_images_token_file_data['calls'] + 1]), 'yaml')); if (Filesystem::has(PATH['uploads'] . '/entries/' . $args['path'])) { + header('Access-Control-Allow-Origin: *'); return $flextype['images']->getImageResponse($args['path'], $_GET); } else { - return $response->withJson([], 404); + return $response + ->withJson([], 404) + ->withHeader('Access-Control-Allow-Origin', '*'); } } } else { - return $response->withJson(["detail" => "Incorrect authentication credentials."], 401); + return $response + ->withJson(["detail" => "Incorrect authentication credentials."], 401) + ->withHeader('Access-Control-Allow-Origin', '*'); } } else { - return $response->withJson(["detail" => "Incorrect authentication credentials."], 401); + return $response + ->withJson(["detail" => "Incorrect authentication credentials."], 401) + ->withHeader('Access-Control-Allow-Origin', '*'); } - return $response->withStatus(404); + return $response + ->withStatus(404) + ->withHeader('Access-Control-Allow-Origin', '*'); } else { - return $response->withJson(["detail" => "Incorrect authentication credentials."], 401); + return $response + ->withJson(["detail" => "Incorrect authentication credentials."], 401) + ->withHeader('Access-Control-Allow-Origin', '*'); } }); diff --git a/flextype/api/delivery/registry.php b/flextype/api/delivery/registry.php index 2189f446..e1510e76 100644 --- a/flextype/api/delivery/registry.php +++ b/flextype/api/delivery/registry.php @@ -53,15 +53,23 @@ $app->get('/api/delivery/registry', function (Request $request, Response $respon Filesystem::write($delivery_registry_token_file_path, $flextype['parser']->encode(array_replace_recursive($delivery_registry_token_file_data, ['calls' => $delivery_registry_token_file_data['calls'] + 1]), 'yaml')); // Return response - return $response->withJson($data, 200); + return $response + ->withJson($data, 200) + ->withHeader('Access-Control-Allow-Origin', '*'); } } else { - return $response->withJson(["detail" => "Incorrect authentication credentials."], 401); + return $response + ->withJson(["detail" => "Incorrect authentication credentials."], 401) + ->withHeader('Access-Control-Allow-Origin', '*'); } } else { - return $response->withJson(["detail" => "Incorrect authentication credentials."], 401); + return $response + ->withJson(["detail" => "Incorrect authentication credentials."], 401) + ->withHeader('Access-Control-Allow-Origin', '*'); } } else { - return $response->withJson(["detail" => "Incorrect authentication credentials."], 401); + return $response + ->withJson(["detail" => "Incorrect authentication credentials."], 401) + ->withHeader('Access-Control-Allow-Origin', '*'); } }); diff --git a/flextype/bootstrap.php b/flextype/bootstrap.php index 3261f270..f3ee0105 100755 --- a/flextype/bootstrap.php +++ b/flextype/bootstrap.php @@ -177,18 +177,6 @@ foreach ($shortcodes_extensions as $shortcodes_extension) { } } -$app->options('/{routes:.+}', function ($request, $response, $args) { - return $response; -}); - -$app->add(function ($req, $res, $next) { - $response = $next($req, $res); - return $response - ->withHeader('Access-Control-Allow-Origin', '*') - ->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization') - ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS'); -}); - /** * Init plugins */ @@ -199,13 +187,6 @@ $flextype['plugins']->init($flextype, $app); */ $flextype['themes']->init($flextype, $app); -// Catch-all route to serve a 404 Not Found page if none of the routes match -// NOTE: make sure this route is defined last -$app->map(['GET', 'POST', 'PUT', 'DELETE', 'PATCH'], '/{routes:.+}', function($req, $res) { - $handler = $this->notFoundHandler; // handle using the default Slim page not found handler - return $handler($req, $res); -}); - /** * Run application */