@proerd/nextpress-context
v0.1.1
Published
## Declare a context mapper
Downloads
10
Readme
nextpress-context
Declare a context mapper
export const jwtContext = createContextMapper({
id: 'default.jwt',
envKeys: ['JWT_SECRET'],
optionalKeys: [],
envContext({ getKey }) {
return {
jwt: {
secret: getKey('JWT_SECRET')!,
},
}
},
})
Add it to the global context type
declare global {
namespace Nextpress {
interface CustomContext extends ReturnType<typeof jwtContext['envContext']> {}
}
}
Declare the application context
const ctx = ContextFactory({
//withPrefix: '...',
projectRoot: __dirname,
mappers: [jwtContext],
})
console.log(ctx.jwt.secret)
- Requires
JWT_SECRET
to be either in the environment variables or inenvfile.env
file; - Unless
NO_ENVFILE
environment variable is set, throws ifenvfile.env
does not exist. Also, creates a new presetenvfile.env
according to the required variables - If
withPrefix
is set, requires variables from a different envfile,<prefix>envfile.env
. Also requires uppercase prefix to be prepended to each environment variable.
TSDX Bootstrap
This project was bootstrapped with TSDX.