diff --git a/api/index.php b/api/index.php index 8e0abf9..1d8ec9f 100644 --- a/api/index.php +++ b/api/index.php @@ -3,7 +3,10 @@ require '../vendor/autoload.php'; if ($_SERVER['QUERY_STRING']) { + header('Content-Type: application/json'); + header('Access-Control-Allow-Origin: *'); echo (new LinkCount(get('page'), get('project'), get('namespaces')))->getJson(); + exit; } diff --git a/includes/LinkCount.php b/includes/LinkCount.php index a0336df..a7fcf7b 100644 --- a/includes/LinkCount.php +++ b/includes/LinkCount.php @@ -233,11 +233,6 @@ public function getHtml() { } public function getJson() { - if (!headers_sent()) { - header('Content-Type: application/json'); - header('Access-Control-Allow-Origin: *'); - } - if (isset($this->error)) { return json_encode(['error' => $this->error]); } diff --git a/includes/ProjectPrefixSearch.php b/includes/ProjectPrefixSearch.php index 5b220c5..1a6811b 100644 --- a/includes/ProjectPrefixSearch.php +++ b/includes/ProjectPrefixSearch.php @@ -28,10 +28,6 @@ public function __construct($prefix) { } public function getJson() { - if (!headers_sent()) { - header('Content-Type: application/json'); - } - return json_encode([ 'projects' => $this->projects, 'exact' => $this->exact diff --git a/projects/index.php b/projects/index.php index 4bb641a..53dd90f 100644 --- a/projects/index.php +++ b/projects/index.php @@ -2,4 +2,5 @@ require '../vendor/autoload.php'; +header('Content-Type: application/json'); echo (new ProjectPrefixSearch(get('prefix')))->getJson();