0.2.0 • Published 8 months ago
@chrishrb/middy-env v0.2.0
middy-env
Simple environment variable middleware for the middy framework. Full typescript support.
Getting started
pnpm install @chrishrb/middy-envOptions
setToContext(boolean) (optional): This will assign the parsed values to the context object of the function handler rather than to process.env. Defaults to true.variables(object) (required): Map of environment variables to parse, where the key is the destination.
Supported Types
stringbooleannumber
Usage
import middy from '@middy/core';
import env, { envVar } from '@chrishrb/middy-env';
const handler = middy(() => {});
// or export it from outside
process.env.MY_EXAMPLE_VARIABLE = 'myValue';
handler
.use(
env({
variables: {
myExampleVariable: envVar<boolean>('MY_EXAMPLE_VARIABLE', 'boolean'),
},
setToContext: true,
}),
)
.before(async (request) => {
// Full typescript support here
console.log(request.context.envVariables.myExampleVariable);
});
await handler(event, context);