Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,51 @@ export default app;
```

The `astro/hono` module exports the same handler names as `astro/fetch` (`astro`, `pages`, `middleware`, `actions`, `sessions`, `redirects`, `cache`, `i18n`, `trailingSlash`), but each returns a Hono middleware function. This lets you mix Astro handlers with any Hono middleware from the ecosystem.

## Cloudflare adapter

The [`@astrojs/cloudflare`](/en/guides/integrations-guide/cloudflare/) adapter provides companion handlers that apply Cloudflare-specific setup to your advanced routing pipeline. These handlers configure session KV binding injection, static asset serving via the `ASSETS` binding, `Astro.locals.cfContext`, client address from the `cf-connecting-ip` header, `waitUntil`, and prerendered error page fetching.

Place the Cloudflare handler before other Astro handlers so that bindings and locals are available to the rest of the pipeline.

### `@astrojs/cloudflare/fetch`

<Since v="13.6.0" pkg="@astrojs/cloudflare" />
Comment thread
ArmandPhilippot marked this conversation as resolved.
Outdated

For use with `astro/fetch`. The `cf()` function receives a `FetchState`, the Cloudflare `env`, and the `ExecutionContext`. It returns a `Response` for static asset hits, or `undefined` when the request should continue to Astro rendering:

```ts title="src/app.ts"
import { astro, FetchState } from 'astro/fetch';
import { cf } from '@astrojs/cloudflare/fetch';

export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
const state = new FetchState(request);
const asset = await cf(state, env, ctx);
if (asset) return asset;
return astro(state);
},
};
```

### `@astrojs/cloudflare/hono`

<Since v="13.6.0" pkg="@astrojs/cloudflare" />
Comment thread
matthewp marked this conversation as resolved.
Outdated

For use with `astro/hono`. The `cf()` function returns a Hono middleware that reads `env` and `executionCtx` from the Hono context automatically:

```ts title="src/app.ts"
import { Hono } from 'hono';
import { actions, middleware, pages, i18n } from 'astro/hono';
import { cf } from '@astrojs/cloudflare/hono';

const app = new Hono<{ Bindings: Env }>();

app.use(cf());
app.use(actions());
app.use(middleware());
app.use(pages());
app.use(i18n());

export default app;
```
Loading