Arguments
-
The API key for the Makeswift site.
-
Options for site version and locale.
Show child attributes
An instance of ReactRuntimeThis function is called when the builder requests the list of fonts available for the site. The function should return an array ofFontFamilyobjects.TheCopyAsk AItype FontFamily { family: string variants: { weight: string style: "normal" | "italic" src?: string }[] }srcfield is used to preview the font in the builder. Thesrcfield can be either a relative or absolute URL. If thesrcfield is omitted, the font is still selectable but uses a fallback font in the builder.An object containing event handlers for the Makeswift site.New in v0.23.12Available events
If defined, this function is called when the site is published.Error handling
Any errors thrown in the event handler will be logged and ignored.Local development
Since onPublish is powered by Makeswift webhooks, it’s not possible to test them locally (e.g., localhost:3000) at this time. We have plans to enable this via tunneling by leveraging the Makeswift CLI but don’t have that ready just yet.
Examples
App Router
src/app/api/makeswift/[...makeswift]/route.ts
Copy
Ask AI
import { MakeswiftApiHandler } from "@makeswift/runtime/next/server";
import { strict } from "assert";
import { runtime } from "@/makeswift/runtime";
// make custom components' data available for introspection
import "@/makeswift/components";
strict(
process.env.MAKESWIFT_SITE_API_KEY,
"MAKESWIFT_SITE_API_KEY is required"
);
const handler = MakeswiftApiHandler(process.env.MAKESWIFT_SITE_API_KEY, {
runtime,
});
export { handler as GET, handler as POST };
Pages router
src/pages/api/makeswift/[...makeswift].ts
Copy
Ask AI
import { MakeswiftApiHandler } from "@makeswift/runtime/next/server";
import { strict } from "assert";
import { runtime } from "@/makeswift/runtime";
// make custom components' data available for introspection
import "@/makeswift/components";
strict(
process.env.MAKESWIFT_SITE_API_KEY,
"MAKESWIFT_SITE_API_KEY is required"
);
export default MakeswiftApiHandler(process.env.MAKESWIFT_SITE_API_KEY, {
runtime,
});
Adding fonts
The following example adds Spline Sans and Spline Sans Mono fonts to the site usingnext/font and adds them to the MakeswiftApiHandler. Using a variable font reduces the number of font files requested.
Copy
Ask AI
import { MakeswiftApiHandler } from "@makeswift/runtime/next/server";
import { strict } from "assert";
import { runtime } from "@/makeswift/runtime";
strict(
process.env.MAKESWIFT_SITE_API_KEY,
"MAKESWIFT_SITE_API_KEY is required"
);
export default MakeswiftApiHandler(process.env.MAKESWIFT_SITE_API_KEY, {
runtime,
getFonts() {
return [
{
family: "Spline Sans",
variants: [
{
weight: "300",
style: "normal",
src: "/fonts/SplineSans-VariableFont.woff2",
},
{
weight: "400",
style: "normal",
src: "/fonts/SplineSans-VariableFont.woff2",
},
{
weight: "500",
style: "normal",
src: "/fonts/SplineSans-VariableFont.woff2",
},
],
},
{
family: "Spline Sans Mono",
variants: [
{
weight: "500",
style: "normal",
src: "/fonts/SplineSansMono-VariableFont.woff2",
},
],
},
];
},
});
Using onPublish event
Copy
Ask AI
import { MakeswiftApiHandler } from "@makeswift/runtime/next/server";
import { strict } from "assert";
import { runtime } from "@/makeswift/runtime";
strict(
process.env.MAKESWIFT_SITE_API_KEY,
"MAKESWIFT_SITE_API_KEY is required"
);
const handler = MakeswiftApiHandler(process.env.MAKESWIFT_SITE_API_KEY, {
runtime,
events: {
onPublish() {
console.log(`Published content`);
},
},
});
export { handler as GET, handler as POST };