tibi-docs/api/hooks/config.js

93 lines
2.6 KiB
JavaScript
Raw Normal View History

2024-03-11 18:14:31 +01:00
const apiSsrBaseURL = "http://localhost:8080/api/v1/_/tibi_starter"
const { frontendBase, tibiUrl, bkdfApiUrl } = require("./config-client")
2023-02-21 14:00:56 +01:00
module.exports = {
2024-03-11 18:14:31 +01:00
operatorEmail: "binkrassdufass.clothing@gmail.com",
operatorName: "BinKrassDuFass",
contactEmail: "binkrassdufass.clothing@gmail.com",
frontendBase,
apiBase: frontendBase + "/api/",
tibiUrl,
2023-11-15 08:00:12 +01:00
apiSsrBaseURL,
2024-03-11 18:14:31 +01:00
ssrValidatePath: function (/** @type {string} */ url) {
//TODO: ANPASSEN!
// -1 = NOTFOUND, 0 = NOSSR, 1 = SSR, "string" = PATH_FOR_CACHE
if (url == "/") {
return 1
}
2023-02-21 14:00:56 +01:00
2024-03-11 18:14:31 +01:00
if (url.match(/^\/(checkout|order|search)/)) {
// no ssr
return 0
}
2023-02-21 14:00:56 +01:00
2024-03-11 18:14:31 +01:00
if (url.match(/^\/service(\/.*)?$/)) {
// static content
return 1
}
const categoryPath = url.replace(/\/[^_\/]+_[^\/]+$/, "") // also in app query
const cat = context.db.find("category", {
2023-02-21 14:00:56 +01:00
filter: {
2024-03-11 18:14:31 +01:00
$or: [
{ "path.de": categoryPath },
{ "path.en": categoryPath },
{ "path.fr": categoryPath },
{ "path.se": categoryPath },
{ "path.dk": categoryPath },
],
},
selector: {
insertTime: 1,
2023-02-21 14:00:56 +01:00
},
})
2024-03-11 18:14:31 +01:00
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
2023-02-21 14:00:56 +01:00
return 1
}
2024-03-11 18:14:31 +01:00
// 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
}
2023-02-21 14:00:56 +01:00
},
2024-03-11 18:14:31 +01:00
2023-11-15 08:00:12 +01:00
ssrPublishCheckCollections: ["content"],
2024-01-27 19:58:35 +01:00
LIGHTHOUSE_TOKEN: "AIzaSyC0UxHp3-MpJiDL3ws7pEV6lj57bfIc7GQ",
2023-02-21 14:00:56 +01:00
}