function createRenderSingletonPageView({ model, editorConfig, view, normalizeForEditor, }) { return async function renderSingletonPageView(req, res) { const doc = await model.getSingle(); const rawData = doc.toObject(); const data = normalizeForEditor ? normalizeForEditor(rawData, req) : rawData; const frontendUrl = process.env.FRONTEND_URL || "http://localhost:3000"; const backendUrl = process.env.BACKEND_URL ?? `${req.protocol}://${req.get("host")}`; const defaultTab = editorConfig.tabs[0]?.key; const requestedTab = req.query.tab; const activeTab = editorConfig.tabs.some((tab) => tab.key === requestedTab) ? requestedTab : defaultTab; return res.render(view, { layout: "layouts/main", title: editorConfig.title, subtitle: editorConfig.subtitle, data, editorConfig, activeTab, frontendUrl, backendUrl, previewUrl: `${frontendUrl}${editorConfig.previewPath}`, currentPath: req.path, user: req.session.user, }); }; } module.exports = createRenderSingletonPageView;