import _ from 'lodash-contrib'; import axios from 'axios'; const productSearchApi = async ({ query, operation = 'OR' }) => { // Use POST for large product ID arrays to avoid URL length limits // GET request URL limit is typically 2KB-8KB; switch to POST if query string is large const QUERY_SIZE_THRESHOLD = 2000; // Switch to POST if query > 2KB if (query.length > QUERY_SIZE_THRESHOLD) { console.log( `[productSearchApi] Large query (${query.length} chars), using POST`, ); // Parse query string into object for POST body const params = new URLSearchParams(query); const bodyData = { ...Object.fromEntries(params), operation, }; const dataProductSearch = await axios.post( `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search`, bodyData, { headers: { 'Content-Type': 'application/json', }, }, ); return dataProductSearch.data; } // Small query, use standard GET request const dataProductSearch = await axios( `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?${query}&operation=${operation}`, ); return dataProductSearch.data; }; export default productSearchApi;