only(['start', 'end', 'type']); $query = array_merge(['type' => 'api'], $query); // Caché por 2 minutos (datos más dinámicos) $cacheKey = "tramites_data_" . md5(serialize($query)); if ($cachedData = Cache::get($cacheKey)) { return response()->json($cachedData, 200) ->header('Content-Type', 'application/json'); } try { $response = Http::timeout(20)->get('https://tramites.comalcalco.gob.mx/reporte-especial', $query); if (!$response->successful()) { Log::warning('Tramites service error', [ 'status' => $response->status(), 'body' => $response->body(), 'query' => $query ]); return response()->json(['error' => 'External service error'], $response->status()); } $data = $response->json(); // Cachear por 2 minutos Cache::put($cacheKey, $data, now()->addMinutes(2)); return response()->json($data, $response->status()) ->header('Content-Type', $response->header('Content-Type', 'application/json')); } catch (\Throwable $e) { Log::error('Proxy error: ' . $e->getMessage(), [ 'query' => $query, 'trace' => $e->getTraceAsString() ]); return response()->json(['error' => 'Unable to contact external service'], 502); } } }