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")}`; return res.render(view, { layout: "layouts/main", title: editorConfig.title, subtitle: editorConfig.subtitle, data, editorConfig, activeTab: req.query.tab || editorConfig.tabs[0].key, frontendUrl, backendUrl, previewUrl: `${frontendUrl}${editorConfig.previewPath}`, currentPath: req.path, user: req.session.user, }); }; } module.exports = createRenderSingletonPageView;