# Migrating from Astro

These tables map Astro to Hamur: its files, its `.astro` syntax, its `client:*` directives, the `Astro` global, its `astro:*` modules, actions, content collections, middleware, endpoints, integrations and adapters. The tables on pages, data and the server in [Migrating from Nuxt](/migrating-from-nuxt) apply to any app. `hamur migrate astro` reads your app and writes `hamur-migration.md`, the same tables filtered to what the app uses; with `--write` it turns each endpoint of `src/pages/` into a handler. It never rewrites an `.astro` file, so the tables are also the checklist for those.

The `Status` column says how close the Hamur way is: `same` means the name and the behavior carry over, `different` means the job has an equivalent that you write another way, and `none` means Hamur has no equivalent today; the row says what to do instead.

## The two models

Astro renders pages to HTML and ships no JavaScript unless a component asks for it with a `client:*` directive. Hamur renders a page on the server and hydrates the whole page in the browser, the way a Nuxt or Next app does. An Astro app is therefore moved in one of two ways:

- **Keep the islands.** A page with `meta.hydrate: "islands"` ships no app entry; only the components you render through `Island` hydrate. This is the nearest to Astro, and it needs `experimental.islands: true`. See [Island pages](/rendering-modes#island-pages).
- **Hydrate the page.** A page that is mostly interactive is an ordinary page, and its navigations stay in the browser.

Astro takes components of several UI libraries in one app. A Hamur app has one library. It is `react`, `preact`, `vue`, `solid`, `svelte` or `html`, set by `framework` in `hamur.config.ts` and installed as `@hamur/adapter-<library>`. An html app may host islands of other libraries; see [html islands and second-library islands](/islands-and-streaming#html-islands-and-second-library-islands).

## Step by step

1. Run `hamur migrate astro` in the app. It changes nothing and writes `hamur-migration.md`: each Astro name the app uses, its Hamur equivalent, the file and line, and whether `--write` can rewrite it.
2. Run `hamur migrate astro --write`. It turns each exported method of an endpoint in `src/pages/` (`GET`, `POST`, …) into a raw handler of `server/routes/`, exported from `server/index.ts`. The original file stays. An endpoint is rewritten only when it reads `params`, `url` and `request` of its context and uses no name of `astro`; any other endpoint is left with its reason in the report. Pages, layouts, components, content collections, middleware and actions are reported and never moved.
3. Install Hamur: `bun remove astro`, then `bun add hamur @hamur/adapter-react`. Pick the adapter of the library most of your components use.
4. Write `hamur.config.ts` from `astro.config.*` ([config keys](#config-keys)).
5. Move `src/pages` to `app/pages`, `src/layouts` to `app/layouts` and `src/components` to `app/components`, then turn each `.astro` file into a component of your library ([Files and folders](#files-and-folders)).
6. Move what the frontmatter of a page fetches into a handler and a `load` ([Data and the `Astro` global](#data-and-the-astro-global)).
7. Turn each `client:*` component into an `Island` ([Islands](#islands)).
8. Move actions and middleware to `server/` ([Actions](#actions), [Middleware](#middleware)), and the endpoints the report left ([Endpoints](#endpoints)).
9. Run `hamur dev`, open each page, then `hamur build`.

## Files and folders

| Astro                                                                           | Hamur                                                   | Status    | Differences                                                                                                                                                                      |
| ------------------------------------------------------------------------------- | ------------------------------------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `astro.config.*`                                                                | `hamur.config.ts`                                       | different | with `defineConfig` of `hamur` and `framework`; the keys are [below](#config-keys)                                                                                               |
| `astro` in `package.json`                                                       | `hamur` and `@hamur/adapter-<library>`                  | different | `bun remove astro`, then `bun add hamur @hamur/adapter-react`; see [Adapters](/adapters)                                                                                         |
| `src/pages/*.astro` and `src/pages/**/*.astro`                                  | `app/pages/**`                                          | same      | one file per route, written as a component of your library; `--write` leaves it. See [Files and routes](/api-reference/routing-details#files-and-routes)                         |
| `src/pages/*.ts`, `src/pages/**/*.ts`, `src/pages/*.js` and `src/pages/**/*.js` | `defineHandler({ route, method, raw: true })`           | different | an endpoint; `--write` writes the handler into `server/routes/`; see [Endpoints](#endpoints)                                                                                     |
| `src/pages/blog/[slug].astro`                                                   | `app/pages/blog/[slug].tsx`                             | same      | the same `[param]` syntax, with the extension of your library. See [Files and routes](/api-reference/routing-details#files-and-routes)                                           |
| `src/pages/[...path].astro`                                                     | `app/pages/[...path].tsx`                               | same      | a catch-all param is a `string[]`; `[[...path]]` also matches the empty path. See [Files and routes](/api-reference/routing-details#files-and-routes)                            |
| `src/pages/404.astro`                                                           | `app/pages/[...slug].tsx` or `app/pages/_not-found.tsx` | different | see [Route conventions](/api-reference/routing-details#route-conventions) and [A URL no page matches](/errors#a-url-no-page-matches)                                             |
| `src/pages/500.astro`                                                           | `app/error.<ext>`                                       | different | the app error page, rendered without a layout; see [The error page](/errors#the-error-page)                                                                                      |
| `src/layouts/**`                                                                | `app/layouts/<name>.<ext>`                              | different | a layout renders `children`; a page picks one with `meta.layout`; see [Layouts](/api-reference/routing-details#layouts)                                                          |
| `src/components/**`                                                             | `app/components/**`                                     | same      | import a component by its path. See [Co-located components](/api-reference/routing-details#co-located-components)                                                                |
| `src/content/**`, `src/content.config.ts` and `src/content.config.js`           | `content/**` and `content.config.ts`                    | different | with `@hamur/content`; see [Content collections](#content-collections)                                                                                                           |
| `src/middleware.ts` and `src/middleware.js`                                     | `defineServer({ middleware })` in `server/index.ts`     | different | see [Middleware](#middleware)                                                                                                                                                    |
| `src/actions/index.ts`                                                          | handlers exported from `server/index.ts`                | different | see [Actions](#actions)                                                                                                                                                          |
| `src/env.d.ts`                                                                  | `.hamur/` types, written by `hamur typegen`             | different | see [TypeScript](/typescript)                                                                                                                                                    |
| `public/`                                                                       | `public/`                                               | same      | see [Directory structure](/directory-structure)                                                                                                                                  |
| `.astro/`                                                                       | `.hamur/`                                               | same      | generated. See [Directory structure](/directory-structure)                                                                                                                       |
| `dist/`                                                                         | `.output/`                                              | different | the build output; see [Build output](/build-output)                                                                                                                              |
| `<script>` in an `.astro` file                                                  | `app/plugins/*.client.ts`, or a component               | none      | Hamur bundles the entry of the app, not a script per page; a script that must run once per page load is a client plugin; see [Plugins and hooks](/plugins-and-hooks#app-plugins) |

## `.astro` components

Hamur has no `.astro` syntax. The frontmatter and the template of an `.astro` file become the data function and the component of your library.

| Astro                                     | Hamur                                                              | Status    | Differences                                                                                                                                                 |
| ----------------------------------------- | ------------------------------------------------------------------ | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| the frontmatter fence `---` of a page     | a `load` in `x.load.ts` beside the page, and handlers in `server/` | different | server code lives in `server/`, never in `app/`; see [Data](/data)                                                                                          |
| the template of an `.astro` file          | the component of your library                                      | none      | JSX, a Vue or Svelte template, or a string for html; rewrite it by hand. See [Adapters](/adapters#the-same-page-in-each-library)                            |
| `<slot />`                                | `children` (Vue: the default slot, Svelte: the `children` snippet) | different | see [Adapters](/adapters#what-differs)                                                                                                                      |
| `<slot name="x" />`                       | a prop that takes an element, or a slot of the library             | different | `@x` folders are parallel route slots, not component slots; see [Slots](/api-reference/routing-details#slots)                                               |
| `<Fragment set:html={html} />`            | the library's raw HTML prop, such as `dangerouslySetInnerHTML`     | different | sanitize the string yourself. See [Adapters](/adapters#what-differs)                                                                                        |
| `class:list`                              | the library's own class syntax                                     | none      | write the string or use a class helper such as `clsx`. See [Styling](/styling)                                                                              |
| `<style>` scoped to a component           | CSS files, CSS modules or the library's scoped style               | different | see [Styling](/styling)                                                                                                                                     |
| `<style is:global>`                       | a global CSS file imported from `app/app.<ext>` or a layout        | different | see [Styling](/styling)                                                                                                                                     |
| `define:vars`                             | a CSS variable set through `style`                                 | none      | see [Styling](/styling)                                                                                                                                     |
| `<head>` elements in a layout             | `useHead`, or the `head` of `hamur.config.ts`                      | different | there is no `<head>` element in a component; see [Head](/head)                                                                                              |
| `Astro.slots`                             | none                                                               | none      | pass the content as a prop. See [Adapters](/adapters#what-differs)                                                                                          |
| `<ViewTransitions />`, `<ClientRouter />` | `app.viewTransition`, `Link viewTransition`                        | different | Hamur navigates in the browser and can run each navigation in a view transition; see [View transitions](/api-reference/navigation-details#view-transitions) |
| `transition:persist`                      | `persist` on an `Island`, or a layout that stays mounted           | different | see [State, children and persisted islands](/islands-and-streaming#state-children-and-persisted-islands)                                                    |
| `transition:name`, `transition:animate`   | `data-hamur-view-transition` and the CSS of the browser            | different | see [View transitions](/api-reference/navigation-details#view-transitions)                                                                                  |

## Islands

Every row of the `client:*` directives is an `on` value of `Island`. `Island` takes a component from `app/islands/`, and its page sets `meta.hydrate: "islands"`. See [Islands](/islands-and-streaming#islands) and [Directives](/islands-and-streaming#directives).

| Astro                                            | Hamur                                                                 | Status    | Differences                                                                                                                                                                      |
| ------------------------------------------------ | --------------------------------------------------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `client:load`                                    | `on="load"` of `Island` from `@hamur/adapter-react`                   | same      | `"load"` is the default. See [Directives](/islands-and-streaming#directives)                                                                                                     |
| `client:idle`                                    | `on="idle"`                                                           | same      | `requestIdleCallback`, else a 200 ms timer; `timeout` option. See [Lazy hydration](/islands-and-streaming#lazy-hydration)                                                        |
| `client:visible`                                 | `on="visible"`                                                        | same      | `IntersectionObserver`; `rootMargin` option. See [Lazy hydration](/islands-and-streaming#lazy-hydration)                                                                         |
| `client:media`                                   | `on={{ media: "(max-width: 50em)" }}`                                 | same      | see [Lazy hydration](/islands-and-streaming#lazy-hydration)                                                                                                                      |
| `client:only`                                    | `on="only"`                                                           | different | renders `fallback` on the server and mounts in the browser; the library is the app's adapter. See [Directives](/islands-and-streaming#directives)                                |
| a component without a directive                  | a component rendered by the page                                      | different | on an island page it renders on the server only; on a full page it hydrates with the page. See [Island pages](/rendering-modes#island-pages)                                     |
| `client:*` props                                 | `props` of `Island`                                                   | different | props are serialized; a function prop fails the render. See [Islands](/islands-and-streaming#islands)                                                                            |
| children of a `client:*` component               | `children` of `Island`                                                | different | rendered on the server only and never hydrated; `on="only"` takes none. See [State, children and persisted islands](/islands-and-streaming#state-children-and-persisted-islands) |
| components of several libraries on one page      | `experimental.islands: { libraries }` in an html app                  | different | see [html islands and second-library islands](/islands-and-streaming#html-islands-and-second-library-islands); in any other app, one library                                     |
| `server:defer`                                   | `ServerIsland` from `@hamur/adapter-react`                            | same      | a component of `app/server-islands/` that renders in its own request, with a `fallback`; see [Server islands](/islands-and-streaming#server-islands)                             |
| a custom `client:` directive from an integration | `addIslandDirective` of `hamur/kit`                                   | same      | see [Directives](/islands-and-streaming#directives)                                                                                                                              |
| `output: "static"` with islands                  | an island page with `routeRules: { "/blog/**": { prerender: true } }` | same      | see [Prerendered pages](/rendering-modes#prerendered-pages)                                                                                                                      |

An island page in code:

````tsx [migrate-astro/app/pages/blog/[slug].tsx]
import { Island, useData, useRoute } from "@hamur/adapter-react"
import type { PageMeta } from "hamur/app"
import LikeButton from "../../islands/LikeButton"

export const meta = { hydrate: "islands" } satisfies PageMeta

export default function Post() {
  const { post } = useData<{ post: { slug: string; title: string } }>()
  const { path } = useRoute()
  return (
    <article>
      <h1>{post.title}</h1>
      <p>{path}</p>
      <Island component={LikeButton} props={{ postId: post.slug }} on="visible" />
    </article>
  )
}
````

````tsx [migrate-astro/app/islands/LikeButton.tsx]
import { useState } from "react"

export default function LikeButton({ postId }: { postId: string }) {
  const [liked, setLiked] = useState(false)
  return (
    <button type="button" aria-label={`Like ${postId}`} onClick={() => setLiked(!liked)}>
      {liked ? "Liked" : "Like"}
    </button>
  )
}
````

## Data and the `Astro` global

A page reads its data in a `load` of `x.load.ts` beside it, which calls a handler. The handler runs only on the server and is a public endpoint, so it checks its input. See [Data](/data).

````ts [migrate-astro/server/blog.ts]
import { createError, defineHandler } from "hamur/server"
import { schema } from "../../migrate-next/server/schema.ts"

const posts = new Map([["hello", { slug: "hello", title: "Hello" }]])

const slugInput = schema<{ slug: string }>(
  { type: "object", properties: { slug: { type: "string" } }, required: ["slug"] },
  (value) => {
    const slug = (value as { slug?: unknown } | undefined)?.slug
    return typeof slug === "string" && slug
      ? { value: { slug } }
      : { issues: [{ message: "A slug is required", path: ["slug"] }] }
  },
)

export const listSlugs = defineHandler({
  method: "GET",
  handler: () => [...posts.keys()],
})

export const getPost = defineHandler({
  method: "GET",
  input: slugInput,
  handler({ slug }) {
    const post = posts.get(slug)
    if (!post) throw createError({ status: 404, message: "Post not found" })
    return post
  },
})
````

````ts [migrate-astro/app/pages/blog/[slug].load.ts]
import { redirect } from "hamur/app"
import type { Entries, Load } from "hamur/app"
import { getPost, listSlugs } from "../../../server/index.ts"

export const entries = (async () => (await listSlugs()).map((slug) => ({ slug }))) satisfies Entries

export const load = (async ({ params }) => {
  if (params.slug === "old") return redirect("/blog/hello", 301)
  return { post: await getPost({ slug: params.slug as string }) }
}) satisfies Load
````

| Astro                                          | Hamur                                                                     | Status    | Differences                                                                                                                                                                        |
| ---------------------------------------------- | ------------------------------------------------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Astro.props` of a page                        | `meta.props: true`, or `useRoute().params`                                | different | a page has no props by default; `meta.props: true` passes the route's params as props, see [Page meta](/api-reference/routing-details#page-meta)                                   |
| `Astro.props` of a component                   | the component's own props                                                 | same      | see [Adapters](/adapters)                                                                                                                                                          |
| `Astro.params`                                 | `useRoute().params` in a component, `params` of the `load` context        | same      | a catch-all is a `string[]`. See [Files and routes](/api-reference/routing-details#files-and-routes)                                                                               |
| `getStaticPaths()`                             | `entries` in the page's `x.load.ts`                                       | different | it returns one object of params per path; `dynamicParams = false` makes them the only paths; see [Pages to prerender](/data#pages-to-prerender-with-entries-and-dynamicparams)     |
| `getStaticPaths` with `props`                  | the `load`, which reads the data again                                    | different | the prerender shares the answers of one run, so a `GET` handler called with one input runs once. See [Shared data](/route-rules#shared-data)                                       |
| `paginate()`                                   | `entries` with a `page` param                                             | none      | write the pages as entries: `[...Array(n).keys()].map((page) => ({ page: String(page + 1) }))`. See [Pages to prerender](/data#pages-to-prerender-with-entries-and-dynamicparams)  |
| `Astro.url`                                    | `useRoute()`, `url` of the `load` context                                 | different | `useRoute()` has `path`, `fullPath`, `query` and `hash`; in a server file `getRequestURL(event)` of `hamur/server`. See [The router](/api-reference/navigation-details#the-router) |
| `Astro.url.searchParams`                       | `useRoute().query`                                                        | different | an object; see [Search params](/api-reference/routing-details#search-params)                                                                                                       |
| `Astro.request`                                | `event.request`                                                           | same      | a Web `Request`; `event` is `ctx.event` of a handler and of a `load` on the server. See [Handlers](/handlers#defining-a-handler)                                                   |
| `Astro.cookies.get(name)`                      | `useCookie(name)` in a component, `getCookie(event, name)` on the server  | different | see [State](/state#cookies)                                                                                                                                                        |
| `Astro.cookies.set(name, value, options)`      | `setCookie(event, name, value, options)`, or `useCookie`                  | different | `setCookie` of `hamur/server`. See [State](/state#cookies)                                                                                                                         |
| `Astro.cookies.delete(name)`                   | `deleteCookie(event, name)`                                               | different | see [State](/state#cookies)                                                                                                                                                        |
| `Astro.locals`                                 | `event.context`                                                           | different | a middleware writes `event.context.user`, a handler and a `load` read it; type the keys with `HamurEventContext`, see [Middleware](/server#middleware)                             |
| `Astro.redirect(location, status)`             | `redirect("/x", 301)` from `hamur/app`                                    | same      | return or throw it from a `load`, route middleware, a request step or a handler. See [`redirect`](/api-reference/app#redirect-isredirect-hamurredirect)                            |
| `Astro.rewrite(path)`                          | `rewrite("/x")` from `hamur/app`                                          | same      | the address stays; a loop of six rewrites answers 508; see [`rewrite`](/api-reference/app#rewrite-isrewrite-hamurrewrite)                                                          |
| `Astro.response.status`, `statusText`          | `setResponseStatus(event, status)`, or `createError({ status })`          | different | see [Errors](/errors)                                                                                                                                                              |
| `Astro.response.headers`                       | `setHeaders` of the `load` context, `event.response.headers` in a handler | different | a `load` sets headers on the document only; in a route a `headers` rule does it by pattern, see [Route rules](/route-rules)                                                        |
| `Astro.clientAddress`                          | `getRequestIP(event)` of `hamur/server`                                   | different | behind a proxy, set `trustedHops`; see [`getRequestIP`](/api-reference/server#getrequestip-getrequesturl)                                                                          |
| `Astro.site`                                   | `site.url`                                                                | different | with `@hamur/seo`; see [Site config](/seo#site-config)                                                                                                                             |
| `Astro.generator`                              | none                                                                      | none      | the page has no generator tag; add one with `useHead` if you want it. See [Head](/head)                                                                                            |
| `Astro.currentLocale`, `Astro.preferredLocale` | `useI18n()` of `@hamur/i18n`, `event.context.locale` on the server        | different | see [Internationalization](/i18n)                                                                                                                                                  |
| `Astro.getActionResult()`                      | `useAction(fn)`                                                           | different | see [Actions](#actions)                                                                                                                                                            |
| `Astro.self`                                   | none; a component imports itself                                          | none      | see [Adapters](/adapters)                                                                                                                                                          |
| `Astro.callAction()`                           | the handler, called as a function on the server                           | different | see [Calling a handler](/handlers#calling-a-handler)                                                                                                                               |
| `export const prerender = true`                | `meta.rules: { prerender: true }`, or a `prerender` route rule            | different | there is no `prerender` export; see [Prerendering a page without params](/data#prerender-a-page)                                                                                   |
| `export const prerender = false`               | the default                                                               | different | a page renders on each request unless a rule prerenders it; `ssr: false` makes it a single-page route. See [Rendering modes](/rendering-modes#server-rendered-pages)               |

## Assets and environment

| Astro                                                      | Hamur                                                 | Status    | Differences                                                                                                                                           |
| ---------------------------------------------------------- | ----------------------------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Image` from `astro:assets`                                | `Img` from `@hamur/image/react`                       | different | with `@hamur/image` in `modules`; `alt` is required, `width` and `height` default to the file's size; see [Showing an image](/image#showing-an-image) |
| `Picture` from `astro:assets`                              | `Picture` from `@hamur/image/react`                   | same      | see [`Picture`](/api-reference/image#picture)                                                                                                         |
| `getImage()`                                               | `getImage(src, modifiers)` from `@hamur/image/server` | same      | for a handler, an OpenGraph tag or a component; see [Image URLs in a handler](/image#image-urls-in-a-handler)                                         |
| `image.domains`, `image.remotePatterns`                    | `image.domains`                                       | different | see [Remote images and limits](/image#remote-images-and-limits)                                                                                       |
| `image.service`                                            | `image.provider`                                      | different | see [Providers](/image#providers-and-where-transforms-run)                                                                                            |
| `experimental.fonts`                                       | `@hamur/fonts`                                        | different | the families go under `fonts`; see [Fonts](/fonts)                                                                                                    |
| `import.meta.env.PUBLIC_X`                                 | `useRuntimeConfig().public.x`, or `#hamur/env/public` | different | see [Environment](/environment)                                                                                                                       |
| `import.meta.env.SECRET`                                   | `#hamur/env/private`                                  | different | server only; the build fails if client code imports it. See [Private and public values](/environment#private-and-public-values)                       |
| `astro:env/server`                                         | `#hamur/env/private`, typed by `defineEnv` of `hamur` | different | see [`app/env.ts`](/environment#appenvts)                                                                                                             |
| `astro:env/client`                                         | `#hamur/env/public`                                   | different | read once, when the page loads. See [Private and public values](/environment#private-and-public-values)                                               |
| `envField.string({ context: "server", access: "secret" })` | `{ schema }` in `defineEnv`, with no `public`         | different | any Standard Schema, or a function that throws on a bad value. See [`app/env.ts`](/environment#appenvts)                                              |
| `envField.number({ context: "client", access: "public" })` | `{ public: true, schema }`                            | different | see [`app/env.ts`](/environment#appenvts)                                                                                                             |
| `envField` with `optional: true` or `default`              | `default` in the entry                                | same      | `default` replaces an unset value, not an empty one. See [`app/env.ts`](/environment#appenvts)                                                        |
| `getSecret()`                                              | `#hamur/env/private`                                  | different | the value is read once, at server start, so an invalid one stops the start. See [When the value is read](/environment#when-the-value-is-read)         |

The environment file is `app/env.ts`:

````ts [typed/app/env.ts]
import { defineEnv } from "hamur"

const port = (raw: string | undefined): number => {
  const value = Number(raw)
  if (!Number.isInteger(value)) throw new Error("must be a number")
  return value
}

export default defineEnv({
  API_KEY: {},
  PORT: { schema: port, default: "3000", description: "Port of the HTTP server" },
  GA_ID: { public: true, description: "Analytics id" },
  SHOW_DEBUG: { public: true, static: true, schema: (raw) => raw === "true", default: "false" },
})
````

## Actions

An Astro action is a typed function that a form or a script calls. In Hamur it is a [handler](/handlers): a function you write with `defineHandler`, export from `server/index.ts` and import in a page from `#server`. A form posts to it, and it works without JavaScript.

````ts [migrate-astro/server/like.ts]
import { defineHandler } from "hamur/server"
import { schema } from "../../migrate-next/server/schema.ts"

const likeInput = schema<{ postId: string }>(
  { type: "object", properties: { postId: { type: "string" } }, required: ["postId"] },
  (value) => {
    const postId = (value as { postId?: unknown } | undefined)?.postId
    return typeof postId === "string" && postId
      ? { value: { postId } }
      : { issues: [{ message: "A post is required", path: ["postId"] }] }
  },
)

export const like = defineHandler({
  input: likeInput,
  handler({ postId }, { event }) {
    event.log.info("liked", { postId })
    return { postId, likes: 1 }
  },
})
````

| Astro                                              | Hamur                                                                        | Status    | Differences                                                                                                                                                                                         |
| -------------------------------------------------- | ---------------------------------------------------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `defineAction({ handler })`                        | `defineHandler({ handler })` from `hamur/server`                             | different | a module-level `export const` of `server/`, written as an object literal; see [Defining a handler](/handlers#defining-a-handler)                                                                    |
| `input: z.object({})`                              | `input: schema`                                                              | different | any Standard Schema; a failed check answers 400 with `data.issues` and `data.values`; see [Validation](/handlers#validation)                                                                        |
| `accept: "form"`                                   | `<Form action={fn}>`                                                         | different | the form is decoded before the handler; see [The `Form` component](/api-reference/forms-details#the-form-component)                                                                                 |
| `accept: "json"`                                   | the default                                                                  | same      | a handler is called with a typed input. See [Calling a handler](/handlers#calling-a-handler)                                                                                                        |
| `actions.like(input)` in a script                  | `like(input)`, imported from `#server`                                       | different | in the browser the call is a request, on the server a function call. See [Calling a handler](/handlers#calling-a-handler)                                                                           |
| `actions.like` in a `<form action>`                | `<Form action={like}>`                                                       | different | works without JavaScript: the form posts to the page with `?_fn=<id>`. See [Without JavaScript](/forms-and-login#without-javascript)                                                                |
| `Astro.getActionResult(actions.like)`              | `useAction(like)`                                                            | different | `state`, `failure`, `error`, `pending` and `result` of `useAction` from `@hamur/adapter-react`. See [Pending state and optimistic UI](/api-reference/forms-details#pending-state-and-optimistic-ui) |
| `isInputError(error)`                              | `failure` of `useAction(fn)`                                                 | different | a 400 with `issues` is the `failure`; see [Reading the result](/api-reference/forms-details#reading-the-result)                                                                                     |
| `ActionError({ code })`                            | `throw createError({ status })` from `hamur/server`, or `fail(status, data)` | different | `fail` takes 400 to 499 and returns the data to the form; see [`fail`](/api-reference/app#fail-isactionfailure-actionfailure)                                                                       |
| `isActionError(error)`                             | `isActionFailure(value)`                                                     | different | see [`isActionFailure`](/api-reference/app#fail-isactionfailure-actionfailure)                                                                                                                      |
| `return redirect()` after a form                   | `return redirect("/x")` from `hamur/app`                                     | same      | a form post is answered with 303. See [Without JavaScript](/forms-and-login#without-javascript)                                                                                                     |
| `getActionContext(context)`                        | `ctx.event` of the handler                                                   | different | see [Defining a handler](/handlers#defining-a-handler)                                                                                                                                              |
| `actions.blog.like` (nested)                       | one export per handler                                                       | different | the name is the name of the export. See [Id and name](/handlers#id-and-name)                                                                                                                        |
| `.orThrow()`                                       | `await like(input)`                                                          | same      | a failed call throws on the client; see [Errors and redirects on the client](/handlers#errors-and-redirects-on-the-client)                                                                          |
| an action as a public endpoint at `/_actions/like` | a handler with a `route`, or the one at `/_hamur/fn/<id>`                    | different | authorize inside every handler; see [Every handler is a public endpoint](/handlers#every-handler-is-a-public-endpoint)                                                                              |
| `security.checkOrigin`                             | `server.originCheck`                                                         | different | `server.originCheck.allow` lists extra origins, `false` turns the check off; see [Sessions and security](/sessions-and-security)                                                                    |

## Content collections

| Astro                                       | Hamur                                                                                   | Status    | Differences                                                                                                                                                         |
| ------------------------------------------- | --------------------------------------------------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `src/content.config.ts`, `defineCollection` | `content.config.ts`, `defineCollection` and `defineContentConfig` from `@hamur/content` | different | at the app root, with `collections` in the default export and `type: "page"` or `"data"`; see [Set it up](/content#set-it-up)                                       |
| `loader: glob({ pattern, base })`           | `source` of the collection, or `glob`                                                   | same      | `source` is the `glob` loader; see [Sources and paths](/content#sources-and-paths)                                                                                  |
| `loader: file("data.json")`                 | `file(path)` of `@hamur/content`, or a `source`                                         | same      | an array gives one entry per item; see [Loaders](/content#loaders)                                                                                                  |
| a custom loader                             | a loader: `{ name, load }`                                                              | different | it calls `store.set`; it runs at build and in `hamur dev`, never at run time; see [Loaders](/content#loaders)                                                       |
| `schema: z.object({})`                      | `schema`                                                                                | same      | any Standard Schema; `image()` is the schema of an image field; see [Schemas](/content#schemas)                                                                     |
| `reference(name)`                           | a field that holds the id, read with a second `queryCollection`                         | none      | there is no reference type. See [Queries](/content#queries)                                                                                                         |
| `getCollection(name)`                       | `queryCollection(name).all()` from `@hamur/content/query`                               | different | a query builder; `where`, `order`, `limit`, `select`, `count`; see [Queries](/content#queries)                                                                      |
| `getCollection(name, filter)`               | `queryCollection(name).where(field, op, value)`                                         | different | see [Queries](/content#queries)                                                                                                                                     |
| `getEntry(name, id)`                        | `queryCollection(name).path(path).first()`                                              | different | see [Queries](/content#queries)                                                                                                                                     |
| `getEntries(refs)`                          | `queryCollection(name).where("id", "IN", ids).all()`                                    | different | see [Queries](/content#queries)                                                                                                                                     |
| `entry.data`                                | the entry's fields                                                                      | different | the fields sit beside `id`, `path` and `body`; `collection`, `id` and `body` are reserved names in frontmatter. See [Sources and paths](/content#sources-and-paths) |
| `render(entry)`                             | `ContentRenderer` from `@hamur/content/react`                                           | different | with `value` and `components`; `renderEntry(entry)` of `@hamur/content/render` gives `{ html, headings, ast }`; see [Render an entry](/content#render-an-entry)     |
| a catch-all page that calls `getEntry`      | `useContentPage(collection)`                                                            | different | sets the head from the entry and throws a 404 when none matches; see [A page for each entry](/content#a-page-for-each-entry)                                        |
| live content collections                    | live collections                                                                        | different | see [Live collections](/content#live-collections)                                                                                                                   |
| MDX                                         | none                                                                                    | none      | Markdown components cover the same job; see [Why there is no MDX](/markdown#why-there-is-no-mdx) and [Markdown components](/markdown#markdown-components)           |
| `@astrojs/markdown-remark` options          | `markdown`                                                                              | different | `remark` and `rehype` plugins go under `markdown`; see [Plugins](/markdown#plugins)                                                                                 |
| Shiki code highlighting                     | `markdown` highlighting                                                                 | different | see [Highlighting](/markdown#highlighting)                                                                                                                          |

## Middleware

`src/middleware.ts` becomes the `middleware` list of `defineServer`. The list runs before every request, in the order written. There is no `sequence`: the list is the sequence.

````ts [migrate-astro/server/middleware.ts]
import { redirect } from "hamur/app"
import { defineMiddleware, getCookie } from "hamur/server"

export const session = defineMiddleware(({ event }) => {
  event.context.user = getCookie(event, "user") ?? null
})

export const admin = defineMiddleware(({ event }) => {
  if (!event.context.user) throw redirect("/login")
})
````

````ts [migrate-astro/server/index.ts]
import { defineServer } from "hamur/server"
import { admin, session } from "./middleware.ts"

export { getPost, listSlugs } from "./blog.ts"
export { like } from "./like.ts"
export { rss } from "./rss.ts"

export default defineServer({
  middleware: [session, { route: "/admin/**", handler: admin }],
})
````

| Astro                                                | Hamur                                                          | Status    | Differences                                                                                                                                                |
| ---------------------------------------------------- | -------------------------------------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `defineMiddleware((context, next) => …)`             | `defineMiddleware(({ event, next }) => …)` from `hamur/server` | different | see [Middleware](/server#middleware)                                                                                                                       |
| `export const onRequest`                             | the `middleware` list of `defineServer`                        | different | in `server/index.ts`. See [Middleware](/server#middleware)                                                                                                 |
| `sequence(a, b)`                                     | `middleware: [a, b]`                                           | same      | outermost first. See [Middleware](/server#middleware)                                                                                                      |
| `context.locals.user = …`                            | `event.context.user = …`                                       | different | the handler and the `load` read it. See [Middleware](/server#middleware)                                                                                   |
| `await next()`                                       | `await next()`                                                 | same      | the code after it sees the answer; a returned `Response` replaces it. See [Middleware](/server#middleware)                                                 |
| `return new Response()`                              | return a value                                                 | same      | returning a value ends the request with it. See [Middleware](/server#middleware)                                                                           |
| `return context.redirect("/login")`                  | `throw redirect("/login")` from `hamur/app`                    | different | a thrown `redirect()` redirects. See [Middleware](/server#middleware)                                                                                      |
| `return next("/other")`, `context.rewrite("/other")` | `return rewrite("/other")` from `hamur/app`                    | same      | the address stays. See [`rewrite`](/api-reference/app#rewrite-isrewrite-hamurrewrite)                                                                      |
| a check on `context.url.pathname`                    | `{ route: "/admin/**", handler }`                              | different | there is no `matcher`; a list entry with a `route` runs only under it. See [Middleware](/server#middleware)                                                |
| a middleware that guards an action                   | `handlerMiddleware`, or `middleware` of the handler            | different | a request step guards the document; the handler's list guards every call; see [Handlers: middleware](/handlers#middleware)                                 |
| middleware of a prerendered page                     | none                                                           | none      | a prerendered page is a file; a guard on it belongs to the host, or the page is not prerendered. See [Rendering modes](/rendering-modes#prerendered-pages) |
| `context.isPrerendered`                              | `import.meta.prerender`                                        | different | `true` while `hamur generate` renders. See [`import.meta.env` and `import.meta.prerender`](/environment#importmetaenv-and-importmetaprerender)             |

## Endpoints

An endpoint file `src/pages/rss.xml.ts` becomes a handler with a `route` and `raw: true`. It gets the request as `event.request` and returns a `Response`. `hamur migrate astro --write` does this for an endpoint that reads only `params`, `url` and `request`: each exported method becomes a handler named `<method><Words>` (`getApiItemsId`) in `server/routes/`, with `[id]` written as `:id` and `[...path]` as `**:path`. A file or folder that starts with `_`, a segment such as `post-[id]`, and an `ALL` export are left for you.

````ts [migrate-astro/server/rss.ts]
import { defineHandler } from "hamur/server"

export const rss = defineHandler({
  route: "/rss.xml",
  method: "GET",
  raw: true,
  handler: () => new Response('<rss version="2.0"></rss>', { headers: { "content-type": "application/xml" } }),
})
````

| Astro                                           | Hamur                                                | Status    | Differences                                                                                                                                                                                 |
| ----------------------------------------------- | ---------------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `src/pages/api/x.ts` with `export const GET`    | a handler with `route: "/api/x"` and `method: "GET"` | different | exported from `server/index.ts`; see [A handler with a route](/server#a-handler-with-a-route)                                                                                               |
| `export const POST: APIRoute`                   | a handler with `method: "POST"`                      | different | one handler for each method. See [A handler with a route](/server#a-handler-with-a-route)                                                                                                   |
| `export const ALL`                              | one handler for each method                          | none      | see [A handler with a route](/server#a-handler-with-a-route)                                                                                                                                |
| `({ request, params, locals }) => Response`     | `(input, { event }) => Response` with `raw: true`    | different | `event.request`, the route params in `getRouterParam(event, name)`, `event.context`; see [`raw`](/api-reference/server-details#raw-a-plain-http-endpoint)                                   |
| `new Response(JSON.stringify(x))`               | return the object                                    | different | a handler returns a value, which is sent as JSON; `raw: true` returns a `Response` as written. See [What a `raw` handler returns](/api-reference/server-details#what-a-raw-handler-returns) |
| a static endpoint, built at `astro build`       | a `GET` handler with `prerender`                     | different | see [Prerender](/handlers#prerender)                                                                                                                                                        |
| `getStaticPaths` of an endpoint                 | `prerender: { inputs }` of the handler               | different | see [Prerender](/handlers#prerender)                                                                                                                                                        |
| `export const prerender = false` in an endpoint | the default                                          | different | see [Prerender](/handlers#prerender)                                                                                                                                                        |
| `rss()` of `@astrojs/rss`                       | a raw handler, or `@hamur/seo` feeds                 | different | see [Feeds](/seo#feeds)                                                                                                                                                                     |
| `sitemap()` of `@astrojs/sitemap`               | `@hamur/seo`                                         | different | see [Sitemap](/seo#sitemap)                                                                                                                                                                 |

## Modules

| Astro                                           | Hamur                                                                               | Status    | Differences                                                                |
| ----------------------------------------------- | ----------------------------------------------------------------------------------- | --------- | -------------------------------------------------------------------------- |
| `defineConfig` of `astro/config`                | `defineConfig` from `hamur`                                                         | different | the config is `hamur.config.ts`; see [Config keys](#config-keys)           |
| `astro:content`                                 | `queryCollection` of `@hamur/content/query`, `defineCollection` of `@hamur/content` | different | see [Content collections](#content-collections)                            |
| `astro:actions`                                 | `defineHandler` from `hamur/server`                                                 | different | see [Actions](#actions)                                                    |
| `astro:middleware`                              | `defineMiddleware` from `hamur/server`                                              | different | see [Middleware](#middleware)                                              |
| `astro:transitions`, `astro:transitions/client` | `app.viewTransition`                                                                | different | see [View transitions](/api-reference/navigation-details#view-transitions) |
| `astro:i18n`                                    | `useI18n()` of `@hamur/i18n`                                                        | different | see [Internationalization](/i18n)                                          |

## Integrations and adapters

| Astro                                                             | Hamur                                                     | Status    | Differences                                                                           |
| ----------------------------------------------------------------- | --------------------------------------------------------- | --------- | ------------------------------------------------------------------------------------- |
| `integrations: [react()]`                                         | `framework: "react"` and `@hamur/adapter-react`           | different | one library for the app; see [Adapters](/adapters)                                    |
| `astro add <name>`                                                | `hamur module add <name>`                                 | different | see [`hamur module`](/cli#hamur-module)                                               |
| an integration's hooks (`astro:config:setup`, `astro:build:done`) | `defineModule` of `hamur/kit`                             | different | a module has `setup` and build hooks; see [Modules](/modules)                         |
| `updateConfig`, `injectRoute`, `addMiddleware` of an integration  | the kit's `extendPages`, `addServerMiddleware` and others | different | see [The kit](/modules#the-kit)                                                       |
| `@astrojs/mdx`                                                    | none                                                      | none      | see [Why there is no MDX](/markdown#why-there-is-no-mdx)                              |
| `@astrojs/sitemap`                                                | `@hamur/seo`                                              | different | see [SEO](/seo)                                                                       |
| `@astrojs/db`                                                     | `@hamur/db`                                               | different | SQL migrations; see [Database](/database)                                             |
| `@astrojs/tailwind` and other CSS tools                           | `@hamur/css`                                              | different | see [Styling](/styling)                                                               |
| `@astrojs/node`, `adapter: node()`                                | `preset: "node"`                                          | same      | see [Presets](/deploy#presets)                                                        |
| `@astrojs/cloudflare`                                             | `preset: "cloudflare"`                                    | same      | `cloudflare-static` and `cloudflare-pages` also exist; see [Presets](/deploy#presets) |
| `@astrojs/vercel`                                                 | `preset: "vercel"`                                        | same      | see [Presets](/deploy#presets)                                                        |
| `@astrojs/netlify`                                                | `preset: "netlify"`                                       | same      | see [Presets](/deploy#presets)                                                        |
| `output: "static"`                                                | `preset: "static"`                                        | same      | every route is prerendered; see [Rendering modes](/rendering-modes)                   |
| `output: "server"`                                                | a server preset                                           | same      | see [Presets](/deploy#presets)                                                        |
| `output: "hybrid"` (Astro 4) or `prerender` per page              | `routeRules` with `prerender`                             | different | see [Route rules and prerender](/route-rules#prerender)                               |
| `i18n` routing                                                    | `i18n` with `@hamur/i18n` in `modules`                    | different | messages use ICU MessageFormat; see [Internationalization](/i18n)                     |
| `astro dev`                                                       | `hamur dev`                                               | same      | see [Dev server](/dev-server)                                                         |
| `astro build`                                                     | `hamur build`                                             | same      | see [CLI](/cli)                                                                       |
| `astro preview`                                                   | `hamur preview`                                           | same      | see [CLI](/cli)                                                                       |
| `astro check`                                                     | `hamur typecheck`                                         | different | see [CLI](/cli)                                                                       |
| the dev toolbar                                                   | `@hamur/devtools`                                         | different | see [Devtools](/devtools)                                                             |

## Config keys

````ts [migrate-astro/hamur.config.ts]
import { defineConfig } from "hamur"
import image from "@hamur/image"
import content from "@hamur/content"
import seo from "@hamur/seo"

export default defineConfig({
  framework: "react",
  preset: "node",
  experimental: { islands: true },
  modules: [image, content, seo],
  app: { baseURL: "/docs/", trailingSlash: "redirect" },
  routeRules: {
    "/old/:slug": { redirect: { to: "/blog/:slug", status: 301 } },
    "/blog/**": { prerender: true },
  },
})
````

| Astro                        | Hamur                                     | Status    | Differences                                                                                                                 |
| ---------------------------- | ----------------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------- |
| `site`                       | `site.url`, with `@hamur/seo`             | different | see [Site config](/seo#site-config)                                                                                         |
| `base`                       | `app.baseURL`                             | same      | it ends with `/`. See [Configuration](/configuration)                                                                       |
| `trailingSlash`              | `app.trailingSlash`                       | different | `"ignore"`, `"redirect"`, `"always"` or `"strict"`; see [Files and routes](/api-reference/routing-details#files-and-routes) |
| `redirects`                  | `routeRules[source] = { redirect }`       | different | `{ redirect: { to, status } }`; a long list is a [redirects file](/route-rules#the-redirects-file)                          |
| `output`, `adapter`          | `preset`                                  | different | see [Presets](/deploy#presets)                                                                                              |
| `integrations`               | `modules`                                 | different | see [Modules](/modules#use-a-module)                                                                                        |
| `server.port`, `server.host` | `devServer`, `hamur dev --port`, `--host` | different | see [CLI](/cli)                                                                                                             |
| `outDir`                     | `outputDir`                               | same      | see [Build output](/build-output)                                                                                           |
| `publicDir`                  | `publicDir`                               | same      | see [Configuration](/configuration)                                                                                         |
| `srcDir`                     | `srcDir`                                  | same      | see [Configuration](/configuration)                                                                                         |
| `vite`                       | `build`, or `@hamur/vite-compat`          | different | `build` is `Bun.build` options; see [Vite plugins](/vite-plugins)                                                           |
| `markdown`                   | `markdown`                                | different | see [The `markdown` key](/markdown#the-markdown-key)                                                                        |
| `image`                      | `image`                                   | different | see [Images](/image)                                                                                                        |
| `env.schema`                 | `app/env.ts`                              | different | see [Environment](/environment)                                                                                             |
| `i18n`                       | `i18n`                                    | different | see [Set it up](/i18n#set-it-up)                                                                                            |
| `devToolbar`                 | `@hamur/devtools` in `modules`            | different | see [Devtools](/devtools)                                                                                                   |
| `prefetch`                   | `app.link`, `Link prefetch`               | different | see [Prefetch](/api-reference/navigation-details#prefetch)                                                                  |
| `experimental`               | `experimental`                            | different | see [Experimental](/experimental)                                                                                           |
