@proerd/nextpress-context
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

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 in envfile.env file;
  • Unless NO_ENVFILE environment variable is set, throws if envfile.env does not exist. Also, creates a new preset envfile.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.

Readme

Keywords

none

Package Sidebar

Install

npm i @proerd/nextpress-context

Weekly Downloads

1

Version

0.1.1

License

none

Unpacked Size

28.5 kB

Total Files

12

Last publish

Collaborators

  • wkrueger128