0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Lazily executed calculating headers in API framework

- if the API controller endpoint is a function, we early return as we
  expect the function to handle the response but we still ended up
  calculating the headers beforehand, only to be thrown away
- this commit moves the header fetching code down in the flow so it's
  only executed when needed
- this doesn't really have a big effect for us because 99% of our
  controllers follow the object pattern
This commit is contained in:
Daniel Lockyer 2022-08-12 08:12:35 +02:00
parent 0f0d21e074
commit c017174c9a

View file

@ -64,7 +64,6 @@ const http = (apiImpl) => {
const result = await apiImpl(frame);
debug(`External API request to ${frame.docName}.${frame.method}`);
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') {
@ -82,6 +81,7 @@ const http = (apiImpl) => {
res.status(statusCode);
// CASE: generate headers based on the api ctrl configuration
const apiHeaders = await headers.get(result, apiImpl.headers, frame) || {};
res.set(apiHeaders);
const send = (format) => {