thinware
A thin middleware wrapper for connecting server-agnostic application logic to req/res/next plumbing.
Installation
# npm npm i --save thinware # yarn yarn add thinware
Example
Let's say we have some server-agnostic application logic in lib/hello.js
that we want to expose via an API endpoint:
module `Hello, !`
Here's what your endpoint might look like:
app
And here's the equivalent with thinware
:
app
thinware.next()
By default, next
is not used. To invoke next
instead of res.send
, use thinware.next
:
app
errdrop support
When thinware
returns errors via res
, it checks for a .status
property on the error before falling back to 500 Internal Server Error
.
This can be done manually, or with a module like errdrop:
const Error = module { if !name throw 'name is required' return `Hello, !`}