summaryrefslogtreecommitdiff
path: root/src/pages/api/shop/searchkey.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/api/shop/searchkey.js')
-rw-r--r--src/pages/api/shop/searchkey.js31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/pages/api/shop/searchkey.js b/src/pages/api/shop/searchkey.js
index 2735e72c..f5546a36 100644
--- a/src/pages/api/shop/searchkey.js
+++ b/src/pages/api/shop/searchkey.js
@@ -1,19 +1,23 @@
import axios from 'axios';
export default async function handler(req, res) {
- const { url = '', page = 1, limit = 30 } = req.query;
+ const { url = '', page = 1, limit = 30, all } = req.query;
let q = '*:*';
- if (!req.query.all) {
- const url = (req.query.q || '').trim();
- q = `keywords_s:"${url}"`;
+ // ✅ kalau BUKAN sitemap
+ if (!all) {
+ const cleanUrl = url.trim();
+ if (!cleanUrl) {
+ return res.status(400).json({ error: 'Missing url param' });
+ }
+ q = `keywords_s:"${cleanUrl}"`;
}
- let offset = (page - 1) * limit;
+
+ const offset = (page - 1) * limit;
const params = [
`q.op=AND`,
- // `q=keywords_s:"${url}"`,
`q=${q}`,
`indent=true`,
`rows=${limit}`,
@@ -21,18 +25,19 @@ export default async function handler(req, res) {
];
try {
- // let result = await axios(
- // process.env.SOLR_HOST + `/solr/searchkey/select?` + params.join('&')
- // );
- let result = await axios.post(
- process.env.SOLR_HOST + `/solr/searchkey/select`,
+ const result = await axios.post(
+ `${process.env.SOLR_HOST}/solr/searchkey/select`,
params.join('&'),
- { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }
+ {
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ },
+ }
);
- console.log(result.data);
res.status(200).json(result.data);
} catch (error) {
+ console.error(error?.response?.data || error);
res.status(500).json({ error: 'Internal Server Error' });
}
}