generated from cms/tibi-docs
backend & types
This commit is contained in:
@@ -6,44 +6,15 @@ const { apiSsrBaseURL, ssrPublishCheckCollections } = require("../config")
|
||||
*
|
||||
* @param {string} cacheKey
|
||||
* @param {string} endpoint
|
||||
* @param {string} query
|
||||
* @param {ApiOptions} options
|
||||
* @returns {ApiResult<any>}
|
||||
* @returns {ApiResult}
|
||||
*/
|
||||
function ssrRequest(cacheKey, endpoint, query, options) {
|
||||
let url = endpoint + (query ? "?" + query : "")
|
||||
|
||||
if (ssrPublishCheckCollections.includes(endpoint)) {
|
||||
// @ts-ignore
|
||||
let validUntil = context.ssrCacheValidUntil
|
||||
|
||||
// check in db for publish date to invalidate cache
|
||||
const _optionsPublishSearch = Object.assign(
|
||||
{},
|
||||
{ filter: options?.filter },
|
||||
{
|
||||
selector: { publishDate: 1 },
|
||||
// projection: null,
|
||||
}
|
||||
)
|
||||
const publishSearch = context.db.find(endpoint, _optionsPublishSearch)
|
||||
publishSearch?.forEach((item) => {
|
||||
const publishDate = item.publishDate ? new Date(item.publishDate.unixMilli()) : null
|
||||
|
||||
if (publishDate && publishDate > new Date()) {
|
||||
// entry has a publish date in the future, set global validUntil
|
||||
if (validUntil == null || validUntil > publishDate) {
|
||||
validUntil = publishDate
|
||||
}
|
||||
}
|
||||
})
|
||||
// @ts-ignore
|
||||
context.ssrCacheValidUntil = validUntil
|
||||
}
|
||||
|
||||
// console.log("############ FETCHING ", apiSsrBaseURL + url)
|
||||
|
||||
const response = context.http.fetch(apiSsrBaseURL + url, {
|
||||
const response = context.http.fetch(apiSsrBaseURL + "/" + url, {
|
||||
method: options.method,
|
||||
headers: options.headers,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user