@financial-times/dotcom-server-app-context
This package provides tools to define FT app context data and a JSON schema definition to validate it with.
Getting started
This package is compatible with Node 8+ and is distributed on npm.
npm install -S @financial-times/dotcom-server-app-context
This package provides a single class which can be configured using options:
import { AppContext } from '@financial-times/dotcom-server-app-context'
const appContext = new AppContext()
The app context instance provides methods to get and set app context data:
appContext.set('appName', 'my-application')
const property = appContext.get('appName')
const contextData = appContext.getAll()
API
get(property: string): any
Returns the value of the requested property.
set(property: string, value: any)
Sets the value of the specified property. The provided value will be validated against the app context schema. If the value is invalid this method will throw an error.
getAll(): object
Returns an immutable copy of the app context data.
Options
The AppContext
class accepts the following parameters. All parameters are optional:
context
An app context data object, see app context data for more information. Defaults to {}
.
App Context Data
Please refer to the JSON schema definition for more information.