Skip to content

Commit

Permalink
feat(indiekit): remove media endpoint resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Jan 31, 2021
1 parent bebcc69 commit 3025aa7
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 47 deletions.
2 changes: 0 additions & 2 deletions packages/indiekit/lib/middleware/locals.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {getNavigation} from '../navigation.js';
import {getMediaEndpoint} from '../publication.js';

/**
* Expose config to frontend templates
Expand All @@ -19,7 +18,6 @@ export const locals = indiekitConfig => {
response.locals.application = application;

// Publication
publication.mediaEndpoint = getMediaEndpoint(publication, request);
response.locals.publication = publication;

// Session
Expand Down
17 changes: 0 additions & 17 deletions packages/indiekit/lib/publication.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,3 @@ export const getPostTypes = publication => {

return [];
};

/**
* Get media endpoint from server derived values
*
* @param {object} publication Publication configuration
* @param {object} request HTTP request
* @returns {string} Media endpoint URL
*/
export const getMediaEndpoint = (publication, request) => {
const {mediaEndpoint} = publication;

if (mediaEndpoint && isUrl(mediaEndpoint)) {
return mediaEndpoint;
}

return `${request.protocol}://${request.headers.host}${mediaEndpoint}`;
};
28 changes: 0 additions & 28 deletions packages/indiekit/tests/lib/publication.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {mongodbConfig} from '../../config/mongodb.js';
import {Cache} from '../../lib/cache.js';
import {
getCategories,
getMediaEndpoint,
getPostTemplate,
getPostTypes
} from '../../lib/publication.js';
Expand Down Expand Up @@ -134,30 +133,3 @@ test('Merges values from custom and preset post types', t => {
test('Returns array if no preset or custom post types', t => {
t.deepEqual(getPostTypes({}), []);
});

test('Gets media endpoint from server derived values', t => {
const request = {
protocol: 'https',
headers: {
host: 'server.example'
}
};

const result = getMediaEndpoint(t.context.publication, request);

t.is(result, 'https://server.example/media');
});

test('Gets media endpoint from publication configuration', t => {
const publication = {mediaEndpoint: 'https://website.example/media'};
const request = {
protocol: 'https',
headers: {
host: 'website.example'
}
};

const result = getMediaEndpoint(publication, request);

t.is(result, 'https://website.example/media');
});

0 comments on commit 3025aa7

Please sign in to comment.