0.1.1 • Published 6 years ago
@proerd/nextpress-context v0.1.1
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_SECRETto be either in the environment variables or inenvfile.envfile; - Unless
NO_ENVFILEenvironment variable is set, throws ifenvfile.envdoes not exist. Also, creates a new presetenvfile.envaccording to the required variables - If
withPrefixis 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.