express-set-headers-mw
v1.0.3
Published
Express middleware to set headers
Downloads
0
Maintainers
Readme
express-headers-setter
Middleware to set response headers in express app
This middleware will help you to set up response headers in 3 different way.
- Static Headers (Value is fixed while configuring this Middleware)
- Dynamically calculated headers (Value is calculated dynamically)
- 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[];
}staticHeaders: This param is of typeIStaticValuesand can be used to configure header with static values.dynamicHeaders: This param is of typeIDynamicValuesand can be used to configure headers with dynamic values.copyFromRequestHeaders: This parameter is array of string and values from request headers will be copied to response headers.
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
Happy codding

