Vue Storefront is now Alokai! Learn More
Installation

Installation

By default, Alokai integration for Storyblok 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 an Storyblok space yet, we suggest you Try For Free on the storyblok website.

Installing dependencies

In your frontend application, install the following dependencies:

yarn
yarn add @vsf-enterprise/storyblok-sdk

In your Server Middleware application, install the following dependencies:

yarn
yarn add @vsf-enterprise/storyblok-api

Adding environment varialbes

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

STORYBLOK_ACCESS_TOKEN=<YOUR_STORYBLOK_ACCESS_TOKEN>
STORYBLOK_PREVIEW_MODE=true || false

Read the Storyblok docs to find out where to get your SpaceId

Configuring Server Middleware

The next step is configuring the Storyblok 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 } from "@vsf-enterprise/storyblok-api";
import type { Integration } from "@vue-storefront/middleware";

const { STORYBLOK_ACCESS_TOKEN, STORYBLOK_PREVIEW_MODE } = process.env;

if (!STORYBLOK_ACCESS_TOKEN) throw new Error("Missing env var: STORYBLOK_ACCESS_TOKEN");
if (!STORYBLOK_PREVIEW_MODE) throw new Error("Missing env var: STORYBLOK_PREVIEW_MODE");

export default {
  integrations: {
    storyblok: {
      location: "@vsf-enterprise/storyblok-api/server",
        configuration: {
          bridge: STORYBLOK_PREVIEW_MODE === "true",
          apiOptions: {
          accessToken: STORYBLOK_ACCESS_TOKEN,
          region: "ap",
          cache: {
             type: "memory",
           },
          },
          unified: {
           resolvePages: () => ({
             "/*": {},
           }),
           resolveFallbackPage: () => ({
             path: "fallback-page",
           }),
        },
      },

    } satisfies Integration<MiddlewareConfig>,
  },
};

Configuring Alokai SDK

The last step in the process is configuring Alokai SDK for Storyblok 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 { storyblokModule } from '@vsf-enterprise/storyblok-sdk';
export type { UnifiedCmsEndpoints } from "@sf-modules-middleware/cms-storyblok";

export function getSdkConfig() {
  return defineSdkConfig(({ buildModule, config }) => ({
      unifiedCms: buildModule(middlewareModule<UnifiedCmsEndpoints>, {
        apiUrl: `${config.middlewareUrl}/cms/unified`,

        defaultRequestConfig: {
          headers: getRequestHeaders(),
        },
      }),
      storyblok: buildModule(storyblokModule, {
        apiUrl: `${config.middlewareUrl}/cms`,
        defaultRequestConfig: {
          headers: getRequestHeaders(),
        },
      }),
  }));
}