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,
  },
});

@pkg-pr-new
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

@github-actions
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
@sam-goodwin sam-goodwin reopened this Oct 31, 2025
@ericclemmons
Copy link
Contributor

From Discord, I'd like to have a stable URL across all environments to rely on.

import.meta.url is a thing, so I wouldn't be surprised to have import.meta.env.* to match.

Screenshot 2025-10-31 at 6 09 44 PM Screenshot 2025-10-31 at 6 09 52 PM

I naturally expected that https://alchemy.run/providers/cloudflare/worker/#self-binding would give me a reference back to SELF.url like worker.url is in my alchemy.run.ts.

But, now I understand that it's a binding to itself (.fetch | .connect).

I cannot import { worker } from ".../alchemy.run.ts" because that has compilation issues in Vite (@libsql, sqlite, Bun, all showed up in the error stack). If it had worked, I would've just used worker.url directly.

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.

4 participants