📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

@hattip/adapter-cloudflare-workers

Package Overview
Dependencies
Maintainers
0
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hattip/adapter-cloudflare-workers

Cloudflare Workers adapter for Hattip

0.0.49
latest
Source
npm
Version published
Weekly downloads
641
23.75%
Maintainers
0
Weekly downloads
 
Created
Source

@hattip/adapter-cloudflare-workers

Hattip adapter for Cloudflare Workers.

Usage

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

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 instead of the service worker format.

context.platform

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. Other bindings like KV or D1 will return undefined. You should use ctx.platform.env to access them instead.

FAQs

Package last updated on 02 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts