# polkadot-middleware

> A middleware pattern for polkadot

Latest version **1.0.1** (published 2019-02-25) · WTFPL license · 0 weekly downloads

## Install

```sh
npm install polkadot-middleware
pnpm add polkadot-middleware
yarn add polkadot-middleware
bun add polkadot-middleware
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-02-25 |
| First published | 2019-02-25 |
| Weekly downloads | 0 |
| License | WTFPL |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | TehShrike |
| Maintainers | tehshrike |
| Keywords | polkadot, http, middleware, server |

## Links

- npm: https://www.npmjs.com/package/polkadot-middleware
- Repository: https://github.com/TehShrike/polkadot-middleware
- Homepage: https://github.com/TehShrike/polkadot-middleware#readme
- Issues: https://github.com/TehShrike/polkadot-middleware/issues
- npm.io page: https://npm.io/package/polkadot-middleware

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-02-25
- 1.0.0 — 2019-02-25

## README

```js
npm i polkadot-middleware
```

So you're using the awesome [polkadot](https://github.com/lukeed/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?

```js
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](https://github.com/tc39/proposal-pipeline-operator), you can use this library to give yourself that sweet linear middleware experience.

```js
const polkadot = require('polkadot')
const middleware = require('polkadot-middleware')

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

# License

[WTFPL](https://wtfpl2.com)

---
_Source: https://npm.io/package/polkadot-middleware · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
