express-headers-setter

Middleware to set response headers in express app

View the Project on GitHub

express-headers-setter

Middleware to set response headers in express app

NPM

Node.js CI FOSSA Status GitHub npms.io (final) npm

This middleware will help you to set up response headers in 3 different way.

  1. Static Headers (Value is fixed while configuring this Middleware)
  2. Dynamically calculated headers (Value is calculated dynamically)
  3. Copying value from response object

Configuring middleware

Middleware can be configured using following method which accepts IConfig parameter

createSetHeadersMiddleware(config:IConfig)

This method will return configured middleware function that sets headers on the response based on configurations.

IConfig

This is interface for configuration parameters

interface IConfig {
    staticHeaders?: IStaticValues;
    dynamicHeaders?: IDynamicValues;
    copyFromRequestHeaders?: string[];
}

#### IStaticValues

interface IStaticValues {
    [key: string]: string;
}

key is header key and value will be header value.. plain and simple.

IDynamicValues

interface IDynamicValues {
    [key: string]: (arg0: Request) => string;
}

key is header key, value is of type function, it will evaluated and request object and return string value will be assigned to header key.

Usage/Example

Here

Happy codding

License

FOSSA Status