@vercel/microfrontends
Version:
Defines configuration and utilities for microfrontends development
69 lines (64 loc) • 2.5 kB
TypeScript
import { NextApiResponse } from 'next';
import { NextResponse } from 'next/server';
import { C as ClientConfig } from '../types-b970b583.js';
import '../types-c9f15465.js';
/**
* Data that is returned from the `.well-known/vercel/microfrontends/client-config`
* endpoint that is used by the client to ensure that navigations and prefetches
* are routed correctly.
*/
interface WellKnownClientData {
config: ClientConfig;
}
/**
* Returns data used by the client to ensure that navigations across
* microfrontend boundaries are routed and prefetched correctly. The client
* configuration is safe to expose to users.
*
* This data should be exposed in a `.well-known/vercel/microfrontends/client-config`
* endpoint.
*/
declare function getWellKnownClientData(clientConfig: string | undefined, flagValues?: Record<string, () => Promise<boolean>>): Promise<WellKnownClientData>;
/**
* A Next.js App Router API handler to export the microfrontends client config
* data.
*
* @example In the `app/.well-known/vercel/microfrontends/client-config/route.ts` file,
* add this code:
* ```
* export { wellKnownNextjsClientConfigAppRoute as GET } from '@vercel/microfrontends/next/endpoints';
* ```
*/
declare function wellKnownNextjsClientConfigAppRoute(flagValues: Record<string, () => Promise<boolean>>): Promise<NextResponse>;
/**
* A Next.js Pages Router API to export the microfrontends client config data to the client.
*
* @example In the `pages/api/.well-known/vercel/microfrontends/client-config/index.ts` file,
* add this code:
* ```
* import { handleClientConfigForPagesRouter } from '@vercel/microfrontends/next/endpoints';
* import type { NextApiResponse } from 'next';
*
* async function handler(
* _,
* res: NextApiResponse,
* ): Promise<void> {
* await handleClientConfigForPagesRouter(res, {
* flagValue: () => Promise.resolve(true)
* });
* }
* ```
*
* Then also make sure to add the following rewrite rule to your `next.config.js` file:
* ```
* rewrites: () =>
* Promise.resolve([
* {
* source: '/.well-known/vercel/microfrontends/client-config',
* destination: '/api/.well-known/vercel/microfrontends/client-config',
* },
* ]),
* ```
*/
declare function handleClientConfigForPagesRouter(res: NextApiResponse, flagValues: Record<string, () => Promise<boolean>>): Promise<void>;
export { WellKnownClientData, getWellKnownClientData, handleClientConfigForPagesRouter, wellKnownNextjsClientConfigAppRoute };