Skip to content

Commit

Permalink
feat: expose nodeHandler and add backward compat with layer as handle
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 29, 2022
1 parent 53f0b58 commit 54a944c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export interface InputLayer {
match?: Matcher
handler: Handler | LazyHandler
lazy?: boolean
/**
* @deprecated
*/
/** @deprecated */
handle?: Handler
/** @deprecated */
promisify?: boolean
}

Expand All @@ -41,6 +41,7 @@ export type NodeHandler = (req: http.IncomingMessage, res: http.ServerResponse)
export interface App extends NodeHandler {
stack: Stack
handler: EventHandler
nodeHandler: NodeHandler
use: AppUse
}

Expand All @@ -67,6 +68,7 @@ export function createApp (options: AppOptions = {}): App {
}

const app = nodeHandler as App
app.nodeHandler = nodeHandler
app.stack = stack
app.handler = handler

Expand Down Expand Up @@ -139,7 +141,7 @@ export function createAppEventHandler (stack: Stack, options: AppOptions) {
}

function normalizeLayer (input: InputLayer) {
let handler = input.handler
let handler = input.handler || input.handle
// @ts-ignore
if (handler.handler) {
// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function callHandler (handler: Middleware, req: IncomingMessage, res: Ser
})
}

export function defineLazyHandler (handler: LazyHandler, promisify?: boolean): PromisifiedHandler {
export function defineLazyHandler (handler: LazyHandler, promisify?: boolean): Handler {
let _promise: Promise<Handler>
const resolve = () => {
if (!_promise) {
Expand All @@ -45,7 +45,7 @@ export function defineLazyHandler (handler: LazyHandler, promisify?: boolean): P
/** @deprecated Use defineLazyHandler */
export const lazyHandle = defineLazyHandler

export function useBase (base: string, handler: PromisifiedHandler): PromisifiedHandler {
export function useBase (base: string, handler: Handler): Handler {
base = withoutTrailingSlash(base)
if (!base) { return handler }
return function (req, res) {
Expand Down

0 comments on commit 54a944c

Please sign in to comment.