# @hattip/adapter-cloudflare-workers

> Cloudflare Workers adapter for Hattip

Latest version **0.0.49** (published 2024-11-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @hattip/adapter-cloudflare-workers
pnpm add @hattip/adapter-cloudflare-workers
yarn add @hattip/adapter-cloudflare-workers
bun add @hattip/adapter-cloudflare-workers
```

## Health

**Score 40/100 (D)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.0.49 |
| Published | 2024-11-02 |
| First published | 2022-04-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 3 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1379 |
| Author | Fatih Aygün |
| Maintainers | cyco130 |

## Links

- npm: https://www.npmjs.com/package/@hattip/adapter-cloudflare-workers
- Repository: https://github.com/hattipjs/hattip
- Homepage: https://github.com/hattipjs/hattip#readme
- Issues: https://github.com/hattipjs/hattip/issues
- npm.io page: https://npm.io/package/@hattip/adapter-cloudflare-workers

## Dependencies (3)

- [@hattip/core](https://npm.io/package/@hattip/core.md) 0.0.49
- [@cloudflare/workers-types](https://npm.io/package/@cloudflare/workers-types.md) ^4.20241022.0
- [@cloudflare/kv-asset-handler](https://npm.io/package/@cloudflare/kv-asset-handler.md) ^0.3.4

## Recent versions

- 0.0.49 (latest) — 2024-11-02
- 0.0.35-canary.7 (canary) — 2023-08-27
- 0.0.48 — 2024-09-08
- 0.0.47 — 2024-08-11
- 0.0.46 — 2024-06-18
- 0.0.45 — 2024-03-27
- 0.0.44 — 2024-03-09
- 0.0.43 — 2024-02-17
- 0.0.42 — 2024-02-07
- 0.0.41 — 2024-01-22
- 0.0.40 — 2024-01-17
- 0.0.39 — 2024-01-15
- 0.0.38 — 2024-01-03
- 0.0.37 — 2023-12-29
- 0.0.36 — 2023-12-29
- … 36 more at https://npm.io/package/@hattip/adapter-cloudflare-workers/versions

## README

# `@hattip/adapter-cloudflare-workers`

Hattip adapter for [Cloudflare Workers](https://workers.cloudflare.com).

## Usage

Assuming you have your Hattip handler defined in `handler.js`, create an entry file like the following and use [`@hattip/bundler-cloudflare-workers`](../../bundler/bundler-cloudflare-workers) or your favorite bundler to bundle it:

```js
import cloudflareWorkersAdapter from "@hattip/adapter-cloudflare-workers";
import handler from "./handler.js";

export default {
  fetch: cloudflareWorkersAdapter(handler),
};
```

If you don't need to serve static files, you can import the adapter from `@hattip/adapter-cloudflare-workers/no-static` instead. You will get an error if you use the default adapter but you don't set up `site = { bucket = "<YOUR STATIC FILES DIR>" }` in your `wrangler.toml`.

`@hattip/adapter-cloudflare-workers` uses the newer [modules format](https://blog.cloudflare.com/workers-javascript-modules) instead of the service worker format.

## `context.platform`

```ts
export interface CloudflareWorkersPlatformInfo {
  /** Platform name */
  name: "cloudflare-workers";
  /**
   * Bindings for secrets, environment variables, and other resources like
   * KV namespaces etc.
   */
  env: unknown;
  /**
   * Execution context
   */
  context: ExecutionContext;
}
```

## Environment variables

The `ctx.env()` function only returns bindings with a string value. Such bindings correspond to [secrets and environment variables](https://developers.cloudflare.com/workers/platform/environment-variables). [Other bindings](https://developers.cloudflare.com/workers/configuration/bindings) like KV or D1 will return `undefined`. You should use `ctx.platform.env` to access them instead.

---
_Source: https://npm.io/package/@hattip/adapter-cloudflare-workers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
