forked from cms/tibi-svelte-starter
✨ refactor: streamline SSR setup and remove Babel configuration
- Updated import path for app.server module in SSR hook. - Removed babel.config.server.json as Babel is no longer needed for async/await transformation. - Adjusted esbuild configuration to target ESNext and modified output paths. - Enhanced App.svelte to handle initial content loading during SSR. - Updated SSR script to load messages synchronously before rendering. - Simplified build:server script in package.json by removing Babel step.
This commit is contained in:
+29
-33
@@ -33,43 +33,39 @@ module.exports = {
|
||||
publishedFilter,
|
||||
ssrValidatePath: function (/** @type {string} */ path) {
|
||||
// validate if path ssr rendering is ok, -1 = NOTFOUND, 0 = NO SSR, 1 = SSR
|
||||
// pe. use context.readCollection("product", {filter: {path: path}}) ... to validate dynamic urls
|
||||
// Starter project: SSR the app shell for language roots and all published content pages.
|
||||
if (path === "/" || path.match(/^\/(de|en)\/?$/)) {
|
||||
return 1
|
||||
}
|
||||
|
||||
// // / is fixed url
|
||||
// if (path == "/cart") return 1
|
||||
const langMatch = path.match(/^\/(de|en)(\/|$)/)
|
||||
const lang = langMatch ? langMatch[1] : null
|
||||
const routePath = lang ? path.replace(/^\/(de|en)(?=\/|$)/, "") || "/" : path
|
||||
|
||||
// // path starts with /products/ is product
|
||||
// if (path?.startsWith("/products/")) {
|
||||
// const slug = path?.replace(/^\/products\//, "")
|
||||
// const resp = context.db.find("product", {
|
||||
// filter: {
|
||||
// $and: [{ slug: slug }, publishedFilter],
|
||||
// },
|
||||
const resp = context.db.find("content", {
|
||||
filter: {
|
||||
$and: [
|
||||
...(lang ? [{ lang: lang }] : []),
|
||||
{ $or: [{ path: routePath }, { "alternativePaths.path": routePath }] },
|
||||
publishedFilter,
|
||||
],
|
||||
},
|
||||
selector: { _id: 1, path: 1, lang: 1 },
|
||||
})
|
||||
if (resp && resp.length) {
|
||||
const canonicalLang = resp[0].lang || lang
|
||||
const canonicalPath = resp[0].path || routePath
|
||||
const canonicalUrl = canonicalLang
|
||||
? `/${canonicalLang}${canonicalPath === "/" ? "" : canonicalPath}`
|
||||
: canonicalPath
|
||||
|
||||
// selector: { _id: 1 },
|
||||
// })
|
||||
// if (resp && resp.length) {
|
||||
// return 1
|
||||
// }
|
||||
// }
|
||||
if (canonicalUrl && canonicalUrl !== path) {
|
||||
return canonicalUrl
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
// // // all other sites are in db
|
||||
// //path = path?.replace(/^\//, "")
|
||||
// const resp = context.db.find("content", {
|
||||
// filter: {
|
||||
// $and: [{ $or: [{ path }, { "alternativePaths.path": path }] }, publishedFilter],
|
||||
// },
|
||||
|
||||
// selector: { _id: 1 },
|
||||
// })
|
||||
// if (resp && resp.length) {
|
||||
// return 1
|
||||
// }
|
||||
|
||||
// not found
|
||||
return -1
|
||||
},
|
||||
ssrPublishCheckCollections: [
|
||||
/*"content", "product"*/
|
||||
],
|
||||
ssrPublishCheckCollections: ["content"],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user