import axios from 'axios'; import { notFound } from 'next/navigation'; import PageNotFound from '../../404'; export default async function handler(req, res) { const { url = '', page = 1, limit = 30, all } = req.query; let q = '*:*'; // ✅ kalau BUKAN sitemap if (!all) { const cleanUrl = url.trim(); if (!cleanUrl) { return res.status(400).json({ error: 'Missing url param' }); } q = `keywords_s:"${cleanUrl}"`; } const offset = (page - 1) * limit; const params = [ `q.op=AND`, `q=${q}`, `indent=true`, `rows=${limit}`, `start=${offset}`, ]; try { const result = await axios.post( `${process.env.SOLR_HOST}/solr/searchkey/select`, params.join('&'), { headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, }, ); const solrResponse = result.data; if (solrResponse.response.numFound === 0) { return res.status(404).json({ error: 'Not Found' }); } else { res.status(200).json(result.data); } } catch (error) { console.error(error?.response?.data || error); res.status(500).json({ error: 'Internal Server Error' }); } }