worker-tools / router

A router for Worker Runtimes such and Cloudflare Workers or Service Workers.
https://workers.tools/router
29 stars 4 forks source link

Unsure how to handle env variables #4

Open shahzeb1 opened 11 months ago

shahzeb1 commented 11 months ago

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.

nounder commented 8 months ago

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({})
    })