Skip to content
AtMyAppDocs
Open dashboard
Get started

Connect any JavaScript website

Use @atmyapp/core with Next.js, SvelteKit, Nuxt, Remix, a Node server or plain browser code.

Open with AI

@atmyapp/core reads content in any JavaScript runtime with fetch: Node 18+, edge runtimes, and browsers. Your framework keeps doing routing, rendering and caching; AtMyApp supplies the data.

Using Astro? Follow the Astro tutorial instead. The integration does steps 4 and 6 for you, and adds previews, SEO tags and forms.

In the dashboard, create a project, then copy:

  • from Settings → API keys: the Project API URL (https://edge.atmyapp.com/v0/projects/<id>) and an API key,
  • from Settings → CLI keys: the atmyapp use … command.

The API key is public and safe in browser code. The CLI key is not. Keys and URLs explains the difference.

Terminal window
npm install @atmyapp/core @atmyapp/structure
npm install --save-dev @atmyapp/cli

Then connect the CLI with the command from Settings → CLI keys:

Terminal window
npx atmyapp use --url https://api.atmyapp.com/v0/projects/<id> --token <cli-key>

Create atmyapp.schema.ts in the project root:

atmyapp.schema.ts
import { defineCollection, defineDocument, defineSchema, s } from "@atmyapp/structure";
export default defineSchema({
definitions: {
home: defineDocument({
fields: {
headline: s.string({ max: 80, description: "Main homepage heading." }),
intro: s.longText({ optional: true }),
},
}),
posts: defineCollection({
fields: {
title: s.string(),
slug: s.slug({ source: "title" }),
excerpt: s.string({ max: 200 }),
cover: s.image({ optional: true }),
},
}),
},
});

Upload it:

Terminal window
npx atmyapp migrate

Then add a homepage and a post or two in the dashboard, and publish them. Websites read published content only, except in previews.

Make one module that creates the client from your environment. Core does not read environment variables itself, so pass the values in:

src/lib/atmyapp.ts
import { createAtMyAppClient } from "@atmyapp/core";
import schema from "../../atmyapp.schema";
export const ama = createAtMyAppClient({
baseUrl: process.env.ATMYAPP_API_URL!,
apiKey: process.env.ATMYAPP_API_KEY!,
schema,
errorPolicy: "throw",
});
.env
ATMYAPP_API_URL=https://edge.atmyapp.com/v0/projects/<id>
ATMYAPP_API_KEY=<api-key>
  • schema makes reads typed: getValue("home") knows about headline, and list("posts") returns posts.
  • errorPolicy: "throw" makes a failed read throw. The default, "quiet-empty", logs a warning and returns empty values. That keeps a browser widget alive, but it can also hide a broken setup or ship an empty static page.
app/page.tsx
import { ama } from "@/lib/atmyapp";
export const revalidate = 60; // refresh published content at most once a minute
export default async function Home() {
const home = await ama.storage.getValue("home");
const posts = await ama.collections.list("posts", { limit: 10 });
return (
<main>
<h1>{home.headline}</h1>
{posts.map((post) => (
<a key={post.slug} href={`/blog/${post.slug}`}>{post.title}</a>
))}
</main>
);
}

Server Components run on the server, so process.env works and the reads never reach the browser.

Set content with textContent or your framework’s normal text binding. Text fields are plain text, not trusted HTML.

How you render When published edits appear What to do
Static build (SSG) After the next build Rebuild on publish. AtMyApp hosting does this for you; elsewhere, see Deploy.
Server rendering On the next request Responses may be cached for up to 60 seconds. Use your framework’s caching (revalidate, Cache-Control) for the rest.
Browser On the next read Nothing. Reads may be cached for up to 60 seconds.

For static builds, keep errorPolicy: "throw" so a failed read fails the build instead of publishing empty pages.

When your client clicks Preview, AtMyApp opens your page with ?amaPreviewKey=… in the URL. To show drafts, create a client per request with that key:

src/lib/atmyapp.ts
import { createAtMyAppClient } from "@atmyapp/core";
import schema from "../../atmyapp.schema";
export function amaForRequest(url: URL) {
const previewKey = url.searchParams.get("amaPreviewKey") ?? undefined;
return createAtMyAppClient({
baseUrl: process.env.ATMYAPP_API_URL!,
apiKey: process.env.ATMYAPP_API_KEY!,
schema,
previewKey,
mode: previewKey ? "priority" : "client",
errorPolicy: "throw",
});
}