Skip to content

Instantly share code, notes, and snippets.

@usulpro
Created November 7, 2019 19:21
Show Gist options
  • Save usulpro/36642bc8f481fc678d61f6b49956f32f to your computer and use it in GitHub Desktop.
Save usulpro/36642bc8f481fc678d61f6b49956f32f to your computer and use it in GitHub Desktop.
// lib/contentful-client.js
const { createClient } = require("contentful");
const { SPACE, DELIVERY_TOKEN, PREVIEW_TOKEN } = require("./contentful-config");
// const { getLocalMocks } = require('./getLocalMocks');
const isProduction = process.env.NODE_ENV === "production";
// const isLocalMocks = !!process.env.LOCAL;
const contentfulClient = createClient({
host: isProduction ? "cdn.contentful.com" : "preview.contentful.com",
accessToken: isProduction ? DELIVERY_TOKEN : PREVIEW_TOKEN,
space: SPACE,
});
const getEntry = entryId => {
// if (isLocalMocks) {
// const entryData = getLocalMocks(entryId);
// return entryData;
// }
return contentfulClient.getEntry(entryId, { include: 2 });
};
module.exports = { contentfulClient, getEntry };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment