diff --git a/routes/settings.js b/routes/settings.js index 6066700..c75937b 100644 --- a/routes/settings.js +++ b/routes/settings.js @@ -101,7 +101,10 @@ module.exports.postSettings = async (request, response, next) => { try { await createClient({ space: spaceId, - accessToken: deliveryToken + accessToken: deliveryToken, + // Environment variable is used here to enable testing this app internally at Contentful. + // You can just omit the host since it defaults to 'cdn.contentful.com' + host: process.env.CONTENTFUL_DELIVERY_API_HOST }).getSpace() } catch (err) { if (err.response.status === 401) { @@ -129,7 +132,9 @@ module.exports.postSettings = async (request, response, next) => { await createClient({ space: spaceId, accessToken: previewToken, - host: 'preview.contentful.com' + // Environment variable is used here to enable testing this app internally at Contentful. + // You should use 'preview.contentful.com' as host to use the preview api + host: process.env.CONTENTFUL_PREVIEW_API_HOST }).getSpace() } catch (err) { if (err.response.status === 401) { diff --git a/services/contentful.js b/services/contentful.js index 500c9f5..fd6c8c5 100644 --- a/services/contentful.js +++ b/services/contentful.js @@ -18,20 +18,25 @@ module.exports.initClients = (options) => { const applicationName = `the-example-app.nodejs/${version}` const config = options || { - spaceId: process.env.CF_SPACE_ID, - deliveryToken: process.env.CF_DELIVERY_TOKEN, - previewToken: process.env.CF_PREVIEW_TOKEN + spaceId: process.env.CONTENTFUL_SPACE_ID, + deliveryToken: process.env.CONTENTFUL_DELIVERY_TOKEN, + previewToken: process.env.CONTENTFUL_PREVIEW_TOKEN } deliveryClient = createClient({ application: applicationName, space: config.spaceId, - accessToken: config.deliveryToken + accessToken: config.deliveryToken, + // Environment variable is used here to enable testing this app internally at Contentful. + // You can just omit the host since it defaults to 'cdn.contentful.com' + host: process.env.CONTENTFUL_DELIVERY_API_HOST }) previewClient = createClient({ application: applicationName, space: config.spaceId, accessToken: config.previewToken, - host: 'preview.contentful.com' + // Environment variable is used here to enable testing this app internally at Contentful. + // You should use 'preview.contentful.com' as host to use the preview api + host: process.env.CONTENTFUL_PREVIEW_API_HOST }) } diff --git a/test/e2e-variables.env b/test/e2e-variables.env index e17e520..7bee1fb 100644 --- a/test/e2e-variables.env +++ b/test/e2e-variables.env @@ -2,6 +2,8 @@ NODE_ENV=development CONTENTFUL_SPACE_ID=qz0n5cdakyl9 CONTENTFUL_DELIVERY_TOKEN=580d5944194846b690dd89b630a1cb98a0eef6a19b860ef71efc37ee8076ddb8 CONTENTFUL_PREVIEW_TOKEN=e8fc39d9661c7468d0285a7ff949f7a23539dd2e686fcb7bd84dc01b392d698b +CONTENTFUL_DELIVERY_API_HOST=cdn.contentful.com +CONTENTFUL_PREVIEW_API_HOST=preview.contentful.com CONTENTFUL_QA_SPACE_ID=jnzexv31feqf CONTENTFUL_QA_DELIVERY_TOKEN=7c1c321a528a25c351c1ac5f53e6ddc6bcce0712ecebec60817f53b35dd3c42b CONTENTFUL_QA_PREVIEW_TOKEN=4310226db935f0e9b6b34fb9ce6611e2061abe1aab5297fa25bd52af5caa531a diff --git a/variables.env b/variables.env index a6b5b33..1429aca 100644 --- a/variables.env +++ b/variables.env @@ -2,4 +2,6 @@ NODE_ENV=development CONTENTFUL_SPACE_ID=qz0n5cdakyl9 CONTENTFUL_DELIVERY_TOKEN=580d5944194846b690dd89b630a1cb98a0eef6a19b860ef71efc37ee8076ddb8 CONTENTFUL_PREVIEW_TOKEN=e8fc39d9661c7468d0285a7ff949f7a23539dd2e686fcb7bd84dc01b392d698b +CONTENTFUL_DELIVERY_API_HOST=cdn.contentful.com +CONTENTFUL_PREVIEW_API_HOST=preview.contentful.com PORT=3000