Vue Storefront is now Alokai! Learn More
Installation

Installation

By default, Alokai integration for Contentful is meant to be used as a Storefront module. However, it can also be installed in any Next or Nuxt application.

Requirements

Bootstrapping Contentful

Before you start using our Contentful integration, you need to bootstrap your Contentful space with Alokai schemas. These schemas are aligned with our out-of-the-box frontend components and are required for the integration to work properly.

The bootstrapping process includes importing integration schemas using Contentful CLI, setting up Live Preview, and managing content types. For detailed instructions, please refer to our Bootstrapping Contentful guide.

If you don't have a Contentful space yet, we suggest you request a demo from the Contentful team.

Installing dependencies

In your frontend application, install the following dependencies:

yarn
yarn add @vsf-enterprise/contentful-sdk

In your Server Middleware application, install the following dependencies:

yarn
yarn add @vsf-enterprise/contentful-api

Adding environment varialbes

In the .env file of your Server Middleware application, add the following envioronment variables:

CNTF_SPACE=<YOUR_CNTF_SPACE>
CNTF_ENVIRONMENT=<YOUR_CNTF_ENVIRONMENT>
CNTF_TOKEN=<YOUR_CNTF_TOKEN>

Information on where to get your Contentful access token from can be found here.

Configuring Server Middleware

The next step is configuring the Contentful integration in the Server Middleware.

Key concept - Server Middleware

Middleware concept is described in detail in our Key concepts: Server Middleware docs.

Add the following configuration to your Server Middleware configuration file.

middleware.config.ts
import type { MiddlewareConfig as ContentfulMiddlewareConfig } from "@vsf-enterprise/contentful-api";
import type { Integration } from "@vue-storefront/middleware";

const { CNTF_TOKEN, CNTF_SPACE, CNTF_ENVIRONMENT } = process.env;

if (!CNTF_TOKEN) throw new Error("Missing env var: CNTF_TOKEN");
if (!CNTF_SPACE) throw new Error("Missing env var: CNTF_SPACE");
if (!CNTF_ENVIRONMENT) throw new Error("Missing env var: CNTF_ENVIRONMENT");

export default {
  integrations: {
    contentful: {
      location: "@vsf-enterprise/contentful-api/server",
      configuration: {
        token: CNTF_TOKEN,
        space: CNTF_SPACE,
        environment: CNTF_ENVIRONMENT,
        unified: {
          resolvePages: () => ({
            "/*": {
              content_type: "page",
            },
          }),
          resolveFallbackPage: () => ({
            path: "/vsf-fallback-page",
            content_type: "page",
          }),
        },
      },
    } satisfies Integration<ContentfulMiddlewareConfig>,
  },
};

Configuring Alokai SDK

The last step in the process is configuring Alokai SDK for Contentful in your frontend application.

Key concept - SDK

SDK core is described in detail in our SDK docs.

Add the following configuration to your SDK modules:

sdk/modules/contentful.ts
import { defineSdkModule } from '@vue-storefront/next';
import { contentfulModule } from '@vsf-enterprise/contentful-sdk';

export const contentful = defineSdkModule(({ buildModule, config }) =>
  buildModule(contentfulModule, {
    apiUrl: `${config.apiUrl}/contentful`,
    ssrApiUrl: `${config.ssrApiUrl}/contentful`,
  }),
);
sdk/modules/index.ts
export * from './contentful';
// ... other module exports