# koa-verify-hostname

> A Koa middleware. Make your Koa application only accessed by designated hostnames.

Latest version **1.0.2** (published 2020-11-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-verify-hostname
pnpm add koa-verify-hostname
yarn add koa-verify-hostname
bun add koa-verify-hostname
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-11-09 |
| First published | 2020-10-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | 17ban |
| Maintainers | 17ban |
| Keywords | koa, koajs, middleware, hostname, verify |

## Links

- npm: https://www.npmjs.com/package/koa-verify-hostname
- npm.io page: https://npm.io/package/koa-verify-hostname

## 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.2 (latest) — 2020-11-09
- 1.0.1 — 2020-10-19
- 1.0.0 — 2020-10-19

## README

# Installation

#### npm

```
npm i -S koa-verify-hostname
```

#### yarn

```
yarn add koa-verify-hostname
```



# Usage

```javascript
const app = new Koa()

const verifyHostname = require('koa-verify-hostname')
app.use(verifyHostname('localhost'))
// access 'localhost' -> next middleware
// access '127.0.0.1' -> response status 403
// access '[::1]' -> response status 403
```

You can also pass into a `RegExp`, or an `Array` contains `string ` and `RegExp `.

```javascript
app.use(verifyHostname(/[a-z]+\.example\.com/i))
// access 'example.com' -> response status 403
// access 'foo.example.com' -> next middleware
// access 'bar.example.com' -> next middleware
// access 'barexample.com' -> response status 403
```

```javascript
app.use(verifyHostname(['example.com', /[a-z]+\.example\.com/i]))
// access 'example.com' -> next middleware
// access 'foo.example.com' -> next middleware
// access 'bar.example.com' -> next middleware
// access 'barexample.com' -> response status 403
```

If you want to customize the response, you can pass a function into `verifyHostname()` as the second argument.

```javascript
app.use(verifyHostname('example.com', async (ctx, next, isValid) => {
	// isValid will be true when accessed by valid hostname
  if(!isValid) {
  	ctx.status = 403
  	ctx.body = 'Invalid Hostname.'
  }
  else
  	await next()
})))
```

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