handle($request); // Add JSON content type for API routes if (strpos($request->getUri()->getPath(), '/api/') === 0) { if (!$response->hasHeader('Content-Type')) { $response = $response->withHeader('Content-Type', 'application/json'); } } return $response; } }