Miss any of our Open RFC calls?Watch the recordings here! »

polkadot-middleware

1.0.1 • Public • Published
npm i polkadot-middleware

So you're using the awesome polkadot server, but you're missing that sweet middleware action – it's a pain to have to compose all those functions yourself, isn't it?

polkadot(
    handleErrors(
        setCacheControl(
            (req, res) => 'Sup dawg'
        )
    )
).listen(8080)
 
function handleErrors(next) {
    return async(req, res) => {
        try {
            return await next(req, res)
        } catch (err) {
            res.statusCode = 500
 
            return err.message || err
        }
    }
}
 
function setCacheControl(next) {
    return async(req, res) => {
        res.setHeader(`Cache-Control`, `public, max-age=` + 3600)
        return next(req, res)
    }
}

Well, until TC39 figures out the pipeline operator, you can use this library to give yourself that sweet linear middleware experience.

const polkadot = require('polkadot')
const middleware = require('polkadot-middleware')
 
middleware(
    polkadot,
    handleErrors,
    setCacheControl,
    (req, res) => 'Sup dawg'
).listen(8080)

License

WTFPL

Install

npm i polkadot-middleware

DownloadsWeekly Downloads

3

Version

1.0.1

License

WTFPL

Unpacked Size

2.38 kB

Total Files

4

Last publish

Collaborators

  • avatar