Skip to content

How to use env in Container envVars #24115

@glav-git

Description

@glav-git

Existing documentation URL(s)

In section Using envVars on the Container class we have the following code snippet:

export class MyContainer extends Container {
  defaultPort = 8080;
  sleepAfter = '10s';
  envVars = {
    ACCOUNT_NAME: env.ACCOUNT_NAME,
    ACCOUNT_API_KEY: env.SECRET_STORE.ACCOUNT_API_KEY,
    CONTAINER_SECRET_KEY: env.CONTAINER_SECRET_KEY,
  };
}

Here env variable is used even though it kinda supposed to be passed only to fetch handler of a worker and the definition of MyContainer class is module-level in all examples.

What changes are you suggesting?

In my opinion documentation need either:

  1. Clarify from where this env variable is imported
  2. if this env variable is not related to env variable in fetch handler of a worker - then it would be better to change it's name in this example or clarify that it's a different variable to avoid confusion
  3. Write an example alternative approach if this usage of env variable in class, that should be defined outside of fetch handler, was demonstrated by mistake

Additional information

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions