Skip to Content
Octopus Energy Packages

Compose Storyblok with other middleware

Preserve routing decisions while applying Storyblok variant rewrites

Use this guide when Storyblok experiments share proxy.ts or middleware.ts with locale, authentication, or other routing middleware.

Resolve Storyblok first

Call the Storyblok middleware on the original request. Its result provides the complete request headers that later middleware and the application must see.

const storyblok = await storyblokMiddleware(request);

Run downstream middleware with its headers

Create the request passed to your router with storyblok.requestHeaders.

import { NextRequest } from "next/server";

const routedRequest = new NextRequest(request, {
  headers: storyblok.requestHeaders,
});
const response = intlMiddleware(routedRequest);

Materialise the final response

Pass the router response to storyblok.response(). This applies identity metadata and refines a pass-through or rewrite response to the selected variant.

return storyblok.response(response);

FAQ

On this page