tibi-docs/api/hooks/config.js
2024-03-11 17:26:10 +00:00

93 lines
2.6 KiB
JavaScript

const apiSsrBaseURL = "http://localhost:8080/api/v1/_/tibi_starter"
const { frontendBase, tibiUrl, bkdfApiUrl } = require("./config-client")
module.exports = {
operatorEmail: "binkrassdufass.clothing@gmail.com",
operatorName: "BinKrassDuFass",
contactEmail: "binkrassdufass.clothing@gmail.com",
frontendBase,
apiBase: frontendBase + "/api/",
tibiUrl,
apiSsrBaseURL,
ssrValidatePath: function (/** @type {string} */ url) {
//TODO: ANPASSEN!
// -1 = NOTFOUND, 0 = NOSSR, 1 = SSR, "string" = PATH_FOR_CACHE
if (url == "/") {
return 1
}
if (url.match(/^\/(checkout|order|search)/)) {
// no ssr
return 0
}
if (url.match(/^\/service(\/.*)?$/)) {
// static content
return 1
}
const categoryPath = url.replace(/\/[^_\/]+_[^\/]+$/, "") // also in app query
const cat = context.db.find("category", {
filter: {
$or: [
{ "path.de": categoryPath },
{ "path.en": categoryPath },
{ "path.fr": categoryPath },
{ "path.se": categoryPath },
{ "path.dk": categoryPath },
],
},
selector: {
insertTime: 1,
},
})
if (cat && cat.length) {
// in category
const matches = url.match(/^\/([^\/]+\/)*([^_\/]+)_/)
if (matches && matches.length > 2) {
// product url
const prod = context.db.find("product", {
filter: {
code: matches[2],
},
selector: {
insertTime: 1,
},
})
if (prod && prod.length) {
// force one url for product code in cache
return categoryPath + "/" + matches[2] + "_ssr-product"
}
// product not found
return -1
}
// try to render category
return 1
}
// search for other content sites
const c = context.db.find("content", {
filter: {
path: url,
},
selector: {
insertTime: 1,
},
})
if (c && c.length) {
// found
return 1
} else {
// not found
return -1
}
},
ssrPublishCheckCollections: ["content"],
LIGHTHOUSE_TOKEN: "AIzaSyC0UxHp3-MpJiDL3ws7pEV6lj57bfIc7GQ",
}