Files
nutriscan/app/api/cache/sync/route.ts
Evandro Fonseca Junior c173fec668 feat(api): implement product caching mechanism
- Add NODE_ENV=production to .env for environment configuration
- Enhance product API route with JSON cache manager for local storage and retrieval
- Introduce cache-only mode and detailed logging for better performance and offline support
- Update UI to display cache status and storage statistics
2025-10-09 04:30:46 -03:00

33 lines
861 B
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { jsonCacheManager } from "@/lib/jsonCacheManager";
export async function POST(request: NextRequest) {
try {
const { products } = await request.json();
if (!products || !Array.isArray(products)) {
return NextResponse.json(
{ error: "Produtos inválidos" },
{ status: 400 }
);
}
// Salvar produtos no cache
const result = await jsonCacheManager.saveProducts(products);
console.log(`[Cache Sync] ${result.saved} novos produtos salvos`);
return NextResponse.json({
success: true,
saved: result.saved,
failed: result.failed,
});
} catch (error) {
console.error("Erro ao sincronizar cache:", error);
return NextResponse.json(
{ error: "Erro ao sincronizar cache" },
{ status: 500 }
);
}
}