Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,53 @@ export default app;
```

`astro/hono` 모듈은 `astro/fetch`와 동일한 핸들러 이름(`astro`, `pages`, `middleware`, `actions`, `sessions`, `redirects`, `cache`, `i18n`, `trailingSlash`)을 내보내지만, 각각은 Hono 미들웨어 함수를 반환합니다. 이를 통해 Astro 핸들러를 Hono 생태계의 다양한 미들웨어와 함께 사용할 수 있습니다.

## Cloudflare 어댑터

[`@astrojs/cloudflare`](/ko/guides/integrations-guide/cloudflare/) 어댑터는 고급 라우팅 파이프라인에 Cloudflare 관련 설정을 적용하는 보조 핸들러를 제공합니다. 이 핸들러들은 세션 KV 바인딩 주입, `ASSETS` 바인딩을 통한 정적 자산 제공, `Astro.locals.cfContext`, `cf-connecting-ip` 헤더에서 클라이언트 주소를 가져오는 기능, `waitUntil`, 그리고 사전 렌더링된 오류 페이지 로드를 구성합니다.

Cloudflare에서는 이 핸들러 없이도 `src/app.ts`의 `astro/fetch` 및 `astro/hono` API를 사용할 수 있습니다. 어댑터의 기본 진입점이 Cloudflare 관련 설정을 자동으로 처리하기 때문입니다. 이러한 보조 핸들러는 예를 들어 Durable Object를 내보내기 위해 이미 [사용자 정의 워커 진입점](https://developers.cloudflare.com/workers/wrangler/configuration/#inheritable-keys)(`src/worker.ts`)을 사용하고 있으며, 해당 파일에서 직접 고급 라우팅 API를 사용하려는 경우에 유용합니다.

워커 진입점에서 이 핸들러를 사용하면 어댑터의 기본 핸들러 기능을 대체하게 되므로 둘을 동시에 사용해서는 안 됩니다. 파이프라인의 나머지 부분에서 바인딩과 locals를 사용할 수 있도록 Cloudflare 핸들러를 다른 Astro 핸들러보다 먼저 배치하세요.

### `@astrojs/cloudflare/fetch`

<p><Since v="13.6.0" pkg="@astrojs/cloudflare" /></p>

`astro/fetch`와 함께 사용합니다. `cf()` 함수는 `FetchState`, Cloudflare의 `env`, 그리고 `ExecutionContext`를 인자로 받습니다. 정적 자산 요청에 대해서는 `Response`를 반환하고, 요청이 Astro 렌더링으로 계속 처리되어야 하는 경우에는 `undefined`를 반환합니다.

```ts title="src/worker.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`

<p><Since v="13.6.0" pkg="@astrojs/cloudflare" /></p>

`astro/hono`와 함께 사용합니다. `cf()` 함수는 Hono 컨텍스트에서 `env`와 `executionCtx`를 자동으로 읽어오는 Hono 미들웨어를 반환합니다:

```ts title="src/worker.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