fast-gateway
Version:
A Node.js API Gateway for the masses!
89 lines (77 loc) • 2 kB
TypeScript
import * as restana from 'restana'
declare namespace fastgateway {
type ProxyType = 'http' | 'lambda' | (string & {})
type Method =
| 'GET'
| 'DELETE'
| 'PATCH'
| 'POST'
| 'PUT'
| 'HEAD'
| 'OPTIONS'
| 'TRACE'
interface Docs {
name: string
endpoint: string
type: string
}
interface ProxyFactoryOpts {
proxyType: ProxyType
opts: {}
route: Route
}
interface Route {
proxyType?: ProxyType
proxyConfig?: {}
proxyHandler?: Function
pathRegex?: string
timeout?: number
prefix: string | RegExp
docs?: Docs
prefixRewrite?: string
target: string
methods?: Method[]
middlewares?: Function[]
urlRewrite?: Function
hooks?: Hooks
disableQsOverwrite?: boolean
}
interface WebSocketRoute {
proxyType: 'websocket'
proxyConfig?: {} // https://github.com/faye/faye-websocket-node#initialization-options
prefix: string
target: string
subProtocols?: [] // https://github.com/faye/faye-websocket-node#subprotocol-negotiation
hooks?: WebSocketHooks
}
interface WebSocketHooks {
onOpen?: (ws: any, searchParams: URLSearchParams) => Promise<void>
}
interface Hooks {
onRequest?: Function
rewriteHeaders?: Function
onResponse?: Function
rewriteRequestHeaders?: Function
request?: {
timeout?: number
[x: string]: any
}
queryString?: string
[x: string]: any
}
interface Options<P extends restana.Protocol> {
server?: Object | restana.Service<P> | Express.Application
proxyFactory?: (opts: ProxyFactoryOpts) => Function | null | undefined
restana?: {}
middlewares?: Function[]
pathRegex?: string
timeout?: number
targetOverride?: string
enableServicesEndpoint?: boolean
routes: (Route | WebSocketRoute)[]
}
}
declare function fastgateway<
P extends restana.Protocol = restana.Protocol.HTTP,
>(opts?: fastgateway.Options<P>): restana.Service<P>
export = fastgateway