UNPKG

817 BJavaScriptView Raw
1'use strict';
2
3const eagerFetch = require('./utils/eager-fetch');
4const fetchres = require('fetchres');
5const logger = require('@financial-times/n-logger').default;
6
7module.exports = function (opts) {
8 const uuid = opts.uuid;
9
10 return eagerFetch('http://api.ft.com/site/v1/pages/' + uuid + '/main-content', {
11 timeout: 3000,
12 headers: {
13 'X-Api-Key': process.env.apikey
14 }
15 })
16 .then(function (response) {
17 if (!response.ok) {
18 logger.warn('Failed getting CAPIv1 page response', {
19 uuid: uuid,
20 type: 'Article',
21 status: response.status
22 });
23 }
24 return response;
25 })
26 .then(fetchres.json)
27 .then(function (page) {
28 const items = page.pageItems.map(function (article) {
29 return article.id;
30 });
31 items.title = page.page.title;
32 return items;
33 });
34};