ssr via fetch
Some checks failed
deploy to production / deploy (push) Failing after 52s

This commit is contained in:
2024-04-10 08:26:40 +00:00
parent 6f1ab474fc
commit 1ebd1424e5
18 changed files with 275 additions and 211 deletions

View File

@@ -1,4 +1,4 @@
const { apiSsrBaseURL, ssrPublishCheckCollections } = require("../config")
const { apiSsrBaseURL } = require("../config")
/**
* api request via server, cache result in context.ssrCache
@@ -6,21 +6,24 @@ const { apiSsrBaseURL, ssrPublishCheckCollections } = require("../config")
*
* @param {string} cacheKey
* @param {string} endpoint
* @param {string} query
* @param {ApiOptions} options
* @returns {ApiResult}
* @returns {ApiResult<any>}
*/
function ssrRequest(cacheKey, endpoint, query, options) {
let url = endpoint + (query ? "?" + query : "")
// 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,
})
// console.log(JSON.stringify(response.headers, null, 2))
const json = response.body.json()
const count = parseInt(response.headers["x-results-count"] || "0")
const count = parseInt(response.headers["X-Results-Count"] || "0")
// json is go data structure and incompatible with js, so we need to convert it
const r = { data: JSON.parse(JSON.stringify(json)), count: count }