feature request: inject special env vars/runtime vars to detect `--local` mode
See original GitHub issueWith miniflare one could inject an environment variable in build scripts to delineate slightly differently between a real worker and one that runs locally.
see
This is helpful to get around the lack of support of secrets so could be used like;
// file: my-app.js
const get_jwt_factory = (secret) =>
HS256({
key: secret,
expires: 86400, // 24 hours
});
export const jwt = (env) => get_jwt_factory(__DEV__ ? 'test-key' : env.JWT_SECRET);
// file: worktop.config.js
import { define } from 'worktop.build';
export default define({
modify(config) {
config.define = {
__DEV__: JSON.stringify(process.env.MINIFLARE === '1'),
};
},
});
would be nice to bring this environment variable back.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Using Environment Variables in Node.js for App Configuration ...
Learn why experienced Node.js developers use environment variables for app config and secrets, including how to manage default values and ...
Read more >Adding Custom Environment Variables | Create React App
Your project can consume variables declared in your environment as if they were declared locally in your JS files.
Read more >Environment variables in Compose | Docker Documentation
How to set, use and manage environment variables in Compose. ... The .env file feature only works when you use the docker-compose up...
Read more >Env Variables and Modes - Vite
Vite exposes env variables on the special import.meta.env object. ... [mode].local # only loaded in specified mode, ignored by git. Env Loading Priorities....
Read more >Configuration and Config Vars - Heroku Dev Center
For example, in a Ruby environment, you could set a RACK_ENV config var to development to enable such a mode. It's important to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We landed initial support for dotenv style injection in https://github.com/cloudflare/wrangler2/pull/879 tldr make a file called .dev.vars in your project root
I think a better solution would be to use environments. In your
wrangler.toml
, you can set upSo you can run
wrangler dev --env dev
and it’ll loadtest-key
.To be clear, this tackles multiple separate issues -
dotenv
support, so you can use.env
files as well.wrangler.toml
/--env
/[vars]
wrangler dev
you can usedev.vars
, which usesdotenv
syntax.I don’t think we have any plans right now to introduce any variables to detect whether we’re running local vs remote modes, but I’ll leave this issue open till we actually discuss and decide. This is also not a regression since we never supported it, and I’ve amended the title to reflect that.