From 9aa5eab5edd1613b31080ae9866e032dadd183d4 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 11 Aug 2022 16:29:08 +0200 Subject: [PATCH] Fixed internal shared framework requires - these requires go outside of the shared folder, and then back in to the index.js - this is confusing and won't work when we pull this code out of core - this commit cleans up the requires to make them more explicit --- ghost/core/core/server/api/shared/http.js | 10 ++++++---- ghost/core/core/server/api/shared/pipeline.js | 15 +++++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ghost/core/core/server/api/shared/http.js b/ghost/core/core/server/api/shared/http.js index 4c6298acde..d47aa85bb8 100644 --- a/ghost/core/core/server/api/shared/http.js +++ b/ghost/core/core/server/api/shared/http.js @@ -1,6 +1,8 @@ const url = require('url'); const debug = require('@tryghost/debug')('api:shared:http'); -const shared = require('../shared'); + +const Frame = require('./frame'); +const headers = require('./headers'); /** * @description HTTP wrapper. @@ -32,7 +34,7 @@ const http = (apiImpl) => { user = req.user.id; } - const frame = new shared.Frame({ + const frame = new Frame({ body: req.body, file: req.file, files: req.files, @@ -62,7 +64,7 @@ const http = (apiImpl) => { const result = await apiImpl(frame); debug(`External API request to ${frame.docName}.${frame.method}`); - const headers = await shared.headers.get(result, apiImpl.headers, frame) || {}; + const apiHeaders = await headers.get(result, apiImpl.headers, frame) || {}; // CASE: api ctrl wants to handle the express response (e.g. streams) if (typeof result === 'function') { @@ -80,7 +82,7 @@ const http = (apiImpl) => { res.status(statusCode); // CASE: generate headers based on the api ctrl configuration - res.set(headers); + res.set(apiHeaders); const send = (format) => { if (format === 'plain') { diff --git a/ghost/core/core/server/api/shared/pipeline.js b/ghost/core/core/server/api/shared/pipeline.js index 1c57f89747..14dd1365e0 100644 --- a/ghost/core/core/server/api/shared/pipeline.js +++ b/ghost/core/core/server/api/shared/pipeline.js @@ -1,10 +1,13 @@ const debug = require('@tryghost/debug')('api:shared:pipeline'); const Promise = require('bluebird'); const _ = require('lodash'); -const shared = require('../shared'); const errors = require('@tryghost/errors'); const {sequence} = require('@tryghost/promise'); +const Frame = require('./frame'); +const serializers = require('./serializers'); +const validators = require('./validators'); + const STAGES = { validation: { /** @@ -32,7 +35,7 @@ const STAGES = { } tasks.push(function doValidation() { - return shared.validators.handle.input( + return validators.handle.input( Object.assign({}, apiConfig, apiImpl.validation), apiUtils.validators.input, frame @@ -60,7 +63,7 @@ const STAGES = { */ input(apiUtils, apiConfig, apiImpl, frame) { debug('stages: input serialisation'); - return shared.serializers.handle.input( + return serializers.handle.input( Object.assign({data: apiImpl.data}, apiConfig), apiUtils.serializers.input, frame @@ -83,7 +86,7 @@ const STAGES = { */ output(response, apiUtils, apiConfig, apiImpl, frame) { debug('stages: output serialisation'); - return shared.serializers.handle.output(response, apiConfig, apiUtils.serializers.output, frame); + return serializers.handle.output(response, apiConfig, apiUtils.serializers.output, frame); } }, @@ -203,9 +206,9 @@ const pipeline = (apiController, apiUtils, apiType) => { } // CASE: http helper already creates it's own frame. - if (!(options instanceof shared.Frame)) { + if (!(options instanceof Frame)) { debug(`Internal API request for ${docName}.${method}`); - frame = new shared.Frame({ + frame = new Frame({ body: data, options: _.omit(options, 'context'), context: options.context || {}