<?php
// Set the content type to JSON
header('Content-Type: application/json');

// Path to the JSON file
$jsonFilePath = '../database/pages.json';

// Check if file exists
if (!file_exists($jsonFilePath)) {
    http_response_code(404);
    echo json_encode(['error' => 'File not found']);
    exit;
}

// Get the contents of the file
$jsonContent = file_get_contents($jsonFilePath);

// Decode to check for JSON validity (optional but recommended)
$data = json_decode($jsonContent, true);

if ($data === null && json_last_error() !== JSON_ERROR_NONE) {
    http_response_code(500);
    echo json_encode(['error' => 'Invalid JSON format in data file']);
    exit;
}

// Return the data as JSON
echo json_encode($data);