import fetch from 'node-fetch';
const {API_TOKEN} = process.env;
exports.handler = async (event,context,callback) => {
const activeCategories = await fetch('/.netlify/functions/getActiveCategories')
const categoriesIdArray = categories.map(category => category.CategoryId);
const productsNested = await Promise.all(categoriesIdArray.map(categoryID => getSearchResults(' ', categoryID)));
callback(null,{
statusCode: 200,
body: JSON.stringify(const productsNested)
})
}
I also tried doing
import getActiveCategories from './getActiveCategories';
and then
const activeCategories = await getActiveCategories()
fetch
as if your calling it from the front-end. Or seperate out the logic in the getActiveCateogires
to an actual function and cal it like your last example
import fetch from 'node-fetch';
const {API_TOKEN} = process.env;
exports.handler = async (event,context,callback) => {
const activeCategoriesRes = await fetch('https://api.example.com/category/GetActiveCategories',{
method: 'GET',
headers: {'APIToken': API_TOKEN}
});
const activeCategoriesData = await activeCategoriesRes.json();
const categories = activeCategoriesData.result;
const categoriesIdArray = categories.map(category => category.CategoryId);
const productsNested = await Promise.all(categoriesIdArray.map(categoryID => {
const categoryProductsRes = await fetch(`http://api.example.com/Product/GetProductSearchByCategory`,{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'APIToken': API_TOKEN
},
body: JSON.stringify({
"CategoryID": CategoryID,
"Search": " ",
"lstBrand": [],
"lstColor": [],
"lstSize": [],
"PriceFrom": 0,
"PriceTo": 0,
"MaxPrice": 0,
"Page": 1,
"Show": 9999,
"UserID": ""
})
})
const categoryProductsData = await categoryProductsRes.json();
return categoryProductsData.result;
}));
const productsList = productsNested.flat();
const hotDeals = productsList.filter(product => product.DiscountPercentage > 15 && product.SellingPrice > 50);
callback(null,{
statusCode: 200,
body: JSON.stringify(hotDeals)
})
}
that it periodically fetches data from the original server, say once every 2 hours and then caches it
The netlify server instance shouldn't stay running longer than a few seconds, or minutes after each call between calls. Thus you will need something running "long term" if you want to cache it for 2 hours
let tobeAdded = `<div>
<p>I am paragraph 1st.</p>
<p>I am paragraph 2nd.</p>
</div>`;
ul.insertAdjacentElement("beforebegin", tobeAdded);
tobeAdded
is a string not element, that's probably causing a problem, haven't dug deep into it though
id
for styling, usually, we use class
, since the class can be used by many elements. Not saying that you can't do this with id
, but id is unique.border: 1px solid black
.<button type="button" class="a-button-nostyle m-country-select">
<img class="a-image icon-flag">
<span>Germany</span>
<div data-component="MDropdownFilter" class="m-dropdown-filter country-dropdown has-error is-open" data-component-id="jjj534jk34j5">
<input placeholder="Germany" class="a-input filter" type="text" required="">
<ul>
<li class="ul-container">
<ul class="options">
<li class="a-option" aria-selected="true">
<a href="/content/p11/page.countryselector.de_DE.de_de.EUR.jsp?goeorguri=%2Fde_de%2Findex.htmltarget="_self" class="a-link is-multilanguage internal-link">German</a>
</li>
<li class="a-option">
<a href="/content/page.countryselector.en_DE.en_de.EUR.jsp?goeorguri=%2Fde_de%2Findex.html%3FdebugClientLibs%3Dtrue" target="_self" class="a-link is-multilanguage internal-link">English</a>
</li>
</ul>
</li>
</ul>
</div>
</button>
import 'React'
and similar? I cannot find anything in my searching of github/tc39 and more general searches. Thanks. Found https://gist.github.com/jkrems/769a8cd8806f7f57903b641c74b5f08a#Future