Skip to content

Conversation

sam-goodwin
Copy link
Collaborator

A Worker by default is allocated a workers.dev subdomain computed from its name and your account's worker subdomain.

E.g.

${workerName}.${subdomain}.workers.dev

Use the Worker.DevDomain and Worker.DevUrl bindings to inject a Worker's own subdomain or URL into its script.

import { Worker } from "alchemy/cloudflare";

const worker = await Worker("api", {
  name: "api-worker",
  entrypoint: "./src/api.ts",
  // workers.dev URL must be enabled (is by default)
  // url: true,
  bindings: {
    // ${workerName}.${subdomain}.workers.dev
    DEV_DOMAIN: Worker.DevDomain,
    // https://${workerName}.${subdomain}.workers.dev
    DEV_URL: Worker.DevUrl,
  },
});

Copy link

pkg-pr-new bot commented Aug 30, 2025

Open in StackBlitz

npm i https://pkg.pr.new/sam-goodwin/alchemy@928

commit: 5c2d786

Copy link

github-actions bot commented Aug 30, 2025

🚀 Website Preview Deployed

Your website preview is ready!

Preview URL: https://d8fabe19-alchemy-website.alchemy-run.workers.dev

This preview was built from commit 670cd79


🤖 This comment will be updated automatically when you push new commits to this PR.

@john-royal
Copy link
Collaborator

john-royal commented Aug 30, 2025

A few questions:

  • Why do we have both DevDomain and DevUrl? How common is it to need the domain without the http(s) prefix?
  • Should this also take worker versions into account? Would definitely make it more complicated since I'm not sure if there's a way to determine the version ID without injecting something into the worker runtime that can read a version metadata binding.

@sam-goodwin
Copy link
Collaborator Author

sam-goodwin commented Sep 1, 2025

Good idea from @Mkassabov, why not just bundle it with other data into a single always-available binding.

type MEtadata = {
  url: string;
  devDomain: string;
  commit: string;
  appName: string;
  stage: string;
  scope: string[];
  // .. what else?
}

@sam-goodwin sam-goodwin force-pushed the main branch 2 times, most recently from a3a4abd to 1eeb802 Compare September 29, 2025 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants