# wildcard-subdomains

> Handle dynamic/wildcard subdomains in Express.js

Latest version **1.1.0** (published 2017-02-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install wildcard-subdomains
pnpm add wildcard-subdomains
yarn add wildcard-subdomains
bun add wildcard-subdomains
```

## 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.1.0 |
| Published | 2017-02-27 |
| First published | 2014-03-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 144 |
| Author | Patrick Moody |
| Maintainers | patmood |

## Links

- npm: https://www.npmjs.com/package/wildcard-subdomains
- Repository: https://github.com/patmood/wildcard-subdomains
- Issues: https://github.com/patmood/wildcard-subdomains/issues
- npm.io page: https://npm.io/package/wildcard-subdomains

## Recent versions

- 1.1.0 (latest) — 2017-02-27
- 1.0.0 — 2016-06-04
- 0.1.0 — 2014-07-25
- 0.0.3 — 2014-03-16
- 0.0.2 — 2014-03-16
- 0.0.1 — 2014-03-16

## README

wildcard-subdomains
==================

[![Build Status](https://travis-ci.org/patmood/wildcard-subdomains.svg?branch=master)](https://travis-ci.org/patmood/wildcard-subdomains) [![npm version](https://badge.fury.io/js/wildcard-subdomains.svg)](https://badge.fury.io/js/wildcard-subdomains)

Handle dynamic/wildcard subdomains in Express.js. Perfect for when you have customized subdomains for different users, and need to handle them within your Node app.

Requests to `foo.yourdomain.com` can be handled with using the route `/_sub/:subdomain`

Paths and query strings and paths remain intact. For example:

`foo.yourdomain.com/post/cat?oh=hai` can be handled with using the route `/_sub/foo/post/cat?oh=hai`

Dependency free!

## How to use

Require the module in app.js:

`var wildcardSubdomains = require('wildcard-subdomains')`

Use the module in middleware:

`app.use(wildcardSubdomains(opts))`

### `opts` - Object
| Key       | Type            | Default  | Description            |
| --------- | --------------- | -------- | ---------------------- |
| namespace | String          | `'_sub'` | Prepended to the path  |
| whitelist | String or Array | `['www']`| Subdomains to ignore   |

Example options:

```
app.use(wildcardSubdomains({
  namespace: 's',
  whitelist: ['www', 'app'],
}))
```

Handle the new route for your subdomain, for example `foo.yourdomain.com` would be handled with:

```
app.get('/s/foo/', function(req, res){
  res.send("Meow!")
})
```

By using the `whiteList` option, requests to `app.yourdomain.com` and `www.yourdomain.com` will be ignored and handled normally.

## Example

`npm run example`

Or check the `examples` directory in this repo

## Protip

For testing subdomains locally, use the domain `vcap.me:3000`

This is a domain that points back to your localhost, allowing you to test subdomains like `foobar.vcap.me`

Running your app behind a proxy? You'll likely need to set the appropriate [trust proxy](http://expressjs.com/en/guide/behind-proxies.html) in express

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