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:
2026-05-12 15:47:53 +00:00
parent e84b87ed16
commit 4a604bab0b
9 changed files with 11844 additions and 51 deletions
+12 -1
View File
@@ -5,7 +5,18 @@ var utils = require("./lib/utils")
const collectionName = col && col.name ? col.name : null
const req = context.request()
const method = req.method
const entryId = (context.data && !Array.isArray(context.data) && context.data.id) || req.param("id") || null
const data = /** @type {Record<string, any>} */ (Array.isArray(context.data) ? {} : context.data || {})
let entryId = data.id || req.param("id") || null
// DELETE hooks may not populate context.data.id or route params consistently.
if (!entryId) {
const path = req.path
const segments = path.split("/")
const last = segments[segments.length - 1]
if (last && last.length >= 24) {
entryId = last
}
}
utils.clearSSRCache(collectionName, entryId, method)
})()
+29 -33
View File
@@ -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"],
}
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -4,6 +4,7 @@ const { release } = require("../config-client")
const { ssrValidatePath } = require("../config")
const { ssrRequest } = require("../lib/ssr-server")
const APP_SERVER_MODULE_PATH = "../lib/app.server"
;(function () {
var request = context.request()
@@ -128,7 +129,7 @@ const { ssrRequest } = require("../lib/ssr-server")
try {
// if error, output plain html without prerendering
// @ts-ignore
const app = require("../lib/app.server")
const app = require(APP_SERVER_MODULE_PATH)
const rendered = app.default.render({
url: url,