router icon indicating copy to clipboard operation
router copied to clipboard

Unsure how to handle env variables

Open shahzeb1 opened this issue 1 year ago • 1 comments

It'd be really helpful if the docs mentioned how to use env vars. I can confirm that without this library, env.SOME_KEY does logged, however, as soon as I export router then the env item in my handler callback doesn't have that value.

Thanks for an awesome library btw.

shahzeb1 avatar Nov 29 '23 07:11 shahzeb1

Access to environmental variables depends on runtime you are using. If you are using Cloudflare Workers, bindings and environmental variables should be available in handler context:

	.put('/:flow_id', async (req, ctx) => {
		ctx.env.KV

		return new JSONResponse({})
	})

nounder avatar Mar 03 '24 12:03 nounder