From 3225b552861d394d0d67caf7076f32559bdde08e Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Tue, 26 Nov 2024 00:46:54 +0000 Subject: [PATCH] style(indiekit): tidy up locals middleware --- packages/indiekit/lib/middleware/locals.js | 36 +++++----------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/packages/indiekit/lib/middleware/locals.js b/packages/indiekit/lib/middleware/locals.js index 3854ec47c..c3d3bb9a6 100644 --- a/packages/indiekit/lib/middleware/locals.js +++ b/packages/indiekit/lib/middleware/locals.js @@ -15,59 +15,39 @@ const cssHash = sha1(await styles()); export const locals = (Indiekit) => async function (request, response, next) { try { - const { - application, - collections, - installedPlugins, - mongodbClientError, - publication, - validationSchemas, - } = Indiekit; - - // Application - request.app.locals.application = application; - // Display MongoDB client connection error - if (mongodbClientError) { - request.app.locals.error = mongodbClientError; + if (Indiekit.mongodbClientError) { + request.app.locals.error = Indiekit.mongodbClientError; } - // Application database collections - application.collections = collections; + // Application + const { application } = Indiekit.config; - // Application locale + application.collections = Indiekit.collections; application.localeUsed = response.locals.getLocale(); - - // Application package application.package = Indiekit.package; - - // Application URL application.url = application.url || getUrl(request); - - // Asset paths application.jsPath = `/assets/app-${jsHash}.js`; application.cssPath = `/assets/app-${cssHash}.css`; - // Application navigation // Only update if serving HTML to prevent wrong session link being shown if (request.accepts("html")) { application.navigation = getNavigation(Indiekit, request, response); } - // Application endpoints request.app.locals.application = { ...application, ...getEndpointUrls(application, request), }; // Installed plug-ins - request.app.locals.installedPlugins = installedPlugins; + request.app.locals.installedPlugins = Indiekit.installedPlugins; // Publication - request.app.locals.publication = publication; + request.app.locals.publication = Indiekit.publication; // Validation schemas - request.app.locals.validationSchemas = validationSchemas; + request.app.locals.validationSchemas = Indiekit.validationSchemas; // Persist scope and token request.app.locals.scope =