-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36ec9c5
commit 14438ad
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { respond } from './tools/respond' | ||
|
||
export function onUse(handle) { | ||
/* | ||
Adapts a Serware `handler` to the [`connect`](https://github.com/senchalabs/connect) API. | ||
Note that the `handler` second argument, `next`, calls the next middleware, preventing any changes to the response object. Nothing is returned by | ||
*/ | ||
return async function (request, response, next) { | ||
request.respond = function (options) { | ||
if (options == null) { | ||
return response | ||
} | ||
if (options.respond != null) { | ||
// If request object is provided, return its response object | ||
return options.respond() | ||
} | ||
return respond(response, options) | ||
} | ||
await handle(request, (request) => { | ||
if (request != null) { | ||
throw new Error( | ||
'Calls to "next" should be performed without any argument.', | ||
) | ||
} | ||
next() | ||
}) | ||
} | ||
} |