diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2026-02-19 10:15:38 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2026-02-19 10:15:38 +0000 |
| commit | 87733bb59bdd6ee3c1b54d006f8465ec1763a0aa (patch) | |
| tree | 130ef14de3f003aab37e003b1ba15dcda166eff4 /src/lib/product/api/productSearchApi.js | |
| parent | 7ef19bc5b5dc64fc0fb8126cec02943f06a4237a (diff) | |
| parent | 6aecb5c1a2ee384b8ea2847a543142bfaa9c48f2 (diff) | |
Merged in cr_renca_keyword (pull request #474)
FEat renca keyword
Diffstat (limited to 'src/lib/product/api/productSearchApi.js')
| -rw-r--r-- | src/lib/product/api/productSearchApi.js | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/lib/product/api/productSearchApi.js b/src/lib/product/api/productSearchApi.js index a84caa3c..1a6ad36a 100644 --- a/src/lib/product/api/productSearchApi.js +++ b/src/lib/product/api/productSearchApi.js @@ -2,8 +2,37 @@ 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}` + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?${query}&operation=${operation}`, ); return dataProductSearch.data; }; |
