GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Nullstack
  • What is Nullstack?
  • Documentation
  • Examples
  • Contributors
  • F.A.Q
  • Waifu
  • Português
  • Star
  • Stateless Components
  • Stateful components
  • Full stack lifecycle
  • Server functions
  • Context

This view

  • Original page
  • New address

GeezerVison is showing nullstack.app — Context Secrets - Nullstack

Context Secrets

  • Type: object
  • Origin: Nullstack Context
  • Availability: server
  • readwrite in server context

You can use it to configure your application with private information.

You can assign any keys with any type to the object.

You can assign keys to secrets dynamically based on current environment using context.environment.

// server.js
import Nullstack from 'nullstack';
import Application from './src/Application';

const context = Nullstack.start(Application);

context.start = function() {
  const { secrets, environment } = context;
  secrets.endpoint = 'https://domain.com/api';
  secrets.privateKey = environment.development ? 'DEV_API_KEY' : 'PROD_API_KEY';
}

export default context;
// src/Application.njs
import Nullstack from 'nullstack';

class Application extends Nullstack {

  static async fetchFromApi({secrets}) {
    const response = await fetch(secrets.endpoint, {
      headers: {
        Authorization: `Bearer ${secrets.privateKey}`
      }
    });
    return await response.json();
  }

}

export default Application;

Any environment variable starting with NULLSTACK_SECRETS_ will be mapped to the secrets in that environment.

🐱‍💻 NULLSTACK_SECRETS_PRIVATE_KEY will be mapped to secrets.privateKey

Next Step

➡️ Learn more about Context Keys: Server request and response❓ Have any questions or suggestions? Join our Discord
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.