polkadot-middleware
A middleware pattern for polkadot
Last updated 2 years ago by tehshrike .
WTFPL · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install polkadot-middleware 
SYNC missed versions from official npm registry.
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

Current Tags

  • 1.0.1                                ...           latest (2 years ago)

2 Versions

  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |