koa-auto-transfer-header
TypeScript icon, indicating that this package has built-in type declarations

1.3.1 • Public • Published

koa-auto-transfer-header

In a Koa server, when a client request is received and an external HTTP request is initiated in the request, the request header initiated by the client is automatically forwarded.

Also used in a server started from any Web Framework.

Support all http-client libs based on http module.

Installation

npm install koa-auto-transfer-header [--save]
or
yarn add koa-auto-transfer-header

Usage

import in portal file

import 'koa-auto-transfer-header';

Config

interface IConfig {
	enable: boolean;		// is enable tranfer, default: true
	transferHeaders: string[],	// transfer header keys, default: ['request-id', 'trace-id']
}

disable transfer

import { disableTransferHeaders } from 'koa-auto-transfer-header';

disableTransferHeaders();

add transfer header

import { addTransferHeader } from 'koa-auto-transfer-header';

addTransferHeader('my-header');

reset transfer headers

import { setTransferHeaders } from 'koa-auto-transfer-header';

setTransferHeaders(['my-header1', 'my-header2']);

add request headers hook

import { RequestHeadersHook } from 'koa-auto-transfer-header';

const foo = () => {
	return { 'x-headers-foo': '123' }
}
const bar = () => {
	return { 'x-headers-bar': '123' }
}
RequestHeadersHook.register(foo)
RequestHeadersHook.register(bar)

// cancel the register
RequestHeadersHook.unregister(foo)

Readme

Keywords

Package Sidebar

Install

npm i koa-auto-transfer-header

Weekly Downloads

40

Version

1.3.1

License

MIT

Unpacked Size

31.9 kB

Total Files

28

Last publish

Collaborators

  • xuezi