Skip to content

Move mikenomitch/hello-world-containers to templates/containers-template #716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 23, 2025

Conversation

th0m
Copy link
Contributor

@th0m th0m commented Jun 20, 2025

Description

Fixes #CC-5506.

Checklist

  • Template Metadata
    • template directory ends with -template
    • "cloudflare" section of package.json is populated
    • template preview image uploaded to Images
    • README is populated and uses <!-- dash-content-start --> and <!-- dash-content-end --> to designate the Dash readme preview
    • package.json contains a deploy command

Example package.json

"cloudflare": {
  "label": "Worker + D1 Database",
  "products": [
    "Workers",
    "D1"
  ],
  "categories": [
    "storage"
  ],
  "docs_url": "https://developers.cloudflare.com/d1/",
  "preview_image_url": "https://imagedelivery.net/wSMYJvS3Xw-n339CbDyDIA/cb7cb0a9-6102-4822-633c-b76b7bb25900/public"
}

@th0m th0m force-pushed the tlefebvre/CC-5506 branch 3 times, most recently from 6362bb8 to 4b2be6e Compare June 21, 2025 00:16
Copy link
Contributor

template name version latestVersion isDevDependency
containers-template @cloudflare/containers ^0.0.8 0.0.8 false
containers-template @cloudflare/workers-types ^4.20250506.0 4.20250620.0 true
containers-template typescript ^5.5.2 5.8.3 true
containers-template wrangler https://pkg.pr.new/wrangler@9098 4.20.5 true

Copy link
Contributor

Preview link not generated: you must be on a branch, not on a fork.
Collaborators may enable previews for this pull request by attaching the allow preview label.
If you are already a collaborator, please create a branch rather than forking.

@th0m
Copy link
Contributor Author

th0m commented Jun 21, 2025

@shaunpersad @deloreyj @cmsparks can one of you please take a look?
Thank you

@mikenomitch
Copy link

@th0m do you need preview images in the package.json?

defaultPort = 8080;
sleepAfter = "2m";
envVars = {
MESSAGE: "I was passed in via the container class!",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit - the way this is interpolated the "!" results in a grammar error

Maybe wrap this in internal quotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, this is how it prints now:
Hi, I'm a container and this is my message: "I was passed in via the container class!", my instance ID is: d037394b-e266-4e55-8b7c-dbd2cb99354d

@th0m
Copy link
Contributor Author

th0m commented Jun 21, 2025

@th0m do you need preview images in the package.json?

Yep I submitted this to get early feedback, working on the images now

@th0m th0m force-pushed the tlefebvre/CC-5506 branch from 4b2be6e to a4bc6f8 Compare June 21, 2025 21:45
Copy link
Contributor

Preview link not generated: you must be on a branch, not on a fork.
Collaborators may enable previews for this pull request by attaching the allow preview label.
If you are already a collaborator, please create a branch rather than forking.

@th0m th0m force-pushed the tlefebvre/CC-5506 branch 2 times, most recently from 688f5a5 to e5ba5dc Compare June 21, 2025 21:50
Copy link
Contributor

Preview link not generated: you must be on a branch, not on a fork.
Collaborators may enable previews for this pull request by attaching the allow preview label.
If you are already a collaborator, please create a branch rather than forking.

@th0m th0m force-pushed the tlefebvre/CC-5506 branch from e5ba5dc to 261e2d5 Compare June 21, 2025 21:52
@th0m th0m force-pushed the tlefebvre/CC-5506 branch from 261e2d5 to 63f5cbd Compare June 21, 2025 22:02
Copy link
Contributor

Preview link not generated: you must be on a branch, not on a fork.
Collaborators may enable previews for this pull request by attaching the allow preview label.
If you are already a collaborator, please create a branch rather than forking.

/* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "Bundler",
/* Specify type package names to be included without being referenced in a source file. */
"types": ["@cloudflare/workers-types/2023-07-01"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't use @cloudflare/workers-types when using worker-configuration.d.ts

This should be ./worker-configuration.d.ts and @cloudflare/workers-types should be removed from package.json dependencies

import { Container, loadBalance, getContainer } from "@cloudflare/containers";

export class MyContainer extends Container {
defaultPort = 8080;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might consider adding comments to these options for users who are less familiar with these (and don't read the docs)

MESSAGE: "I was passed in via the container class!",
};

override onStart() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be worth adding a comment above these explaining that these are optional


// To route requests to a specific container,
// pass a unique container identifier to .get()
if (pathname.startsWith("/container")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider converting this routing logic to a Hono router. I know this is a hello-world example, but a router is needed to build anything meaningful. New users who use this may not know a router exists and end up going way too far with this style of routing and feeling like Workers is difficult to use.

Defaults make a big difference in user experience

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to this. The initial simplicity of path-based routing quickly turns into a stumbling block for new users. We are in the process of adding Hono as a requirement to the Contributor Guidelines.

@deloreyj deloreyj added the allow preview allows for preview links on forks label Jun 23, 2025
Copy link
Contributor

template name version latestVersion isDevDependency
containers-template @cloudflare/containers ^0.0.8 0.0.10 false
containers-template @cloudflare/workers-types ^4.20250506.0 4.20250620.0 true
containers-template typescript ^5.5.2 5.8.3 true
containers-template wrangler https://pkg.pr.new/wrangler@9098 4.20.5 true

Copy link
Contributor

Dashboard preview link

- Replace @cloudflare/workers-types with ./worker-configuration.d.ts in tsconfig.json
- Remove @cloudflare/workers-types from package.json dependencies
- Add Hono for better routing and developer experience
- Add helpful comments for container configuration options
- Convert manual pathname parsing to clean Hono route handlers
"devDependencies": {
"@cloudflare/workers-types": "^4.20250506.0",
"typescript": "^5.5.2",
"wrangler": "https://pkg.pr.new/wrangler@9098"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will we be able to update this to an actual wrangler version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later today, wrangler team cutting a release right now

@th0m
Copy link
Contributor Author

th0m commented Jun 23, 2025

I believe I have addressed your comments, ready for review.

Copy link
Contributor

template name version latestVersion isDevDependency
containers-template @cloudflare/containers ^0.0.10 0.0.10 false
containers-template hono ^4.8.2 4.8.2 false
containers-template typescript ^5.5.2 5.8.3 true
containers-template wrangler https://pkg.pr.new/wrangler@main 4.20.5 true

Copy link
Contributor

Dashboard preview link

@th0m th0m force-pushed the tlefebvre/CC-5506 branch from e82df14 to c08bc71 Compare June 23, 2025 20:42
Copy link
Contributor

template name version latestVersion isDevDependency
containers-template @cloudflare/containers ^0.0.10 0.0.10 false
containers-template hono ^4.8.2 4.8.2 false
containers-template typescript ^5.5.2 5.8.3 true
containers-template wrangler ^4.21.0 4.21.0 true

Copy link
Contributor

Dashboard preview link

@deloreyj deloreyj merged commit 9635cab into cloudflare:main Jun 23, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
allow preview allows for preview links on forks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants