Skip to content
Merged
Show file tree
Hide file tree
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 @@ -478,6 +478,7 @@ export const LocalWorkerProvider = () =>
]),
),
domains: [url],
routes: [],
crons: Array.from(
new Set([...getCronBindings(bindings), ...(props.crons ?? [])]),
),
Expand Down Expand Up @@ -545,6 +546,7 @@ export const LocalWorkerProvider = () =>
tags: [],
durableObjectNamespaces,
domains: url ? [url] : [],
routes: [],
crons: Array.from(
new Set([...getCronBindings(bindings), ...(news.crons ?? [])]),
),
Expand Down Expand Up @@ -576,6 +578,7 @@ export const LocalWorkerProvider = () =>
durableObjectNamespaces: {},
accountId,
domains: [],
routes: [],
crons: news.crons ?? [],
} satisfies Worker["Attributes"];
}
Expand Down
42 changes: 42 additions & 0 deletions packages/alchemy/src/Cloudflare/Workers/Worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type { DevOrigin } from "../Hyperdrive/Connection.ts";
import type { Providers } from "../Providers.ts";
import type { DispatchNamespace } from "../WorkersForPlatforms/DispatchNamespace.ts";
import type { WorkflowExport } from "../Workflows/Workflow.ts";
import type { Reference as ZoneReference } from "../Zone/lookup.ts";
import { type Assets, type AssetsProps } from "./Assets.ts";
import { type DurableObjectExport } from "./DurableObject.ts";
import { Request } from "./Request.ts";
Expand Down Expand Up @@ -295,6 +296,28 @@ export type NormalizedBindings<

export type WorkerAssetsConfig = string | AssetsProps | AssetsWithHash;

export interface WorkerRouteConfig {
/**
* URL pattern to match incoming requests against, e.g.
* `"subdomain.example.com/*"` or `"example.com/api/*"`.
*/
pattern: string;
/**
* Cloudflare zone ID. Equivalent to Wrangler's `zone_id`.
*/
zoneId?: string;
/**
* Cloudflare zone name, e.g. `"example.com"`. Equivalent to Wrangler's
* `zone_name`.
*/
zoneName?: string;
/**
* Zone reference — a zone ID, zone name, or `{ zoneId, name? }` object.
* Alternative to `zoneId` / `zoneName`.
*/
zone?: ZoneReference;
}

export interface WorkerProps<
Bindings extends WorkerBindingProps = any,
Assets extends WorkerAssetsConfig | undefined =
Expand Down Expand Up @@ -441,6 +464,13 @@ export interface WorkerProps<
* already exist in the account.
*/
domain?: string | string[];
/**
* Zone routes that map URL patterns to this Worker. Equivalent to Wrangler's
* `routes` array — provide `zoneName` or `zoneId` (or `zone`) alongside each
* `pattern`. When the zone is omitted, it is inferred from the pattern's
* hostname.
*/
routes?: WorkerRouteConfig[];
/**
* Extra bundler options applied on top of the standard rolldown input/output
* options used to build this Worker. See {@link Bundle.BundleExtraOptions}.
Expand Down Expand Up @@ -579,6 +609,7 @@ export type Worker<Bindings extends WorkerBindings = any> = Resource<
durableObjectNamespaces: Record<string, string>;
accountId: string;
domains: string[];
routes: { id: string; pattern: string; zoneId: string }[];
crons: string[];
hash?: {
assets: string | undefined;
Expand Down Expand Up @@ -796,6 +827,17 @@ export type Worker<Bindings extends WorkerBindings = any> = Resource<
* }
* ```
*
* @example Zone routes
* ```typescript
* {
* main: import.meta.filename,
* routes: [
* { pattern: "api.example.com/*", zoneName: "example.com" },
* { pattern: "example.com/api/*", zoneId: "<YOUR_ZONE_ID>" },
* ],
* }
* ```
*
* @example Deploying a prebuilt Worker without bundling
* When `main` already points at a complete, runtime-ready ESM bundle
* produced by an external tool (e.g. OpenNext), set `bundle: false` to
Expand Down
Loading