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

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 Alokai SDK configuration file:

sdk.config.ts
import { contentfulModule } from '@vsf-enterprise/contentful-sdk';

export function getSdkConfig() {
  return defineSdkConfig(({ buildModule, config }) => ({
    contentful: buildModule(contentfulModule, {
      apiUrl: `${config.middlewareUrl}/contentful`
    }),
  }));
}