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
This commit is contained in:
parent
dc0cec56ea
commit
9aa5eab5ed
@ -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') {
|
||||
|
@ -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 || {}
|
||||
|
Loading…
Reference in New Issue
Block a user