subdomains
Version:
A hapi plugin which extracts subdomains from uri
118 lines (86 loc) • 2.95 kB
Markdown
# subdomains
[](https://www.npmjs.com/package/subdomains/v/latest)
[](https://npmjs.com/package/subdomains/v/latest)
[](https://www.npmjs.com/package/npm)
[](https://codecov.io/gh/vemarav/subdomains)
[](https://travis-ci.com/vemarav/subdomains)
[](https://github.com/vemarav/subdomains)
This plugin supprots only [Hapi](https://hapijs.com)
**subdomains** plugin adds subdomains & subdomain properties to request object
## Usage
```js
// file: server.js
const subdomains = require("subdomains");
server.register({
plugin: subdomains,
options: {
// provide domain name for better results
domainName: "yourdomain.co.in",
// provide subdomains to exclude
// or an empty array
exclude: ["www", "api"]
}
});
```
## Example
http://users.kiprosh.trackive.com
```js
// file server.js
"use strict";
const subdomains = require("subdomains");
const Hapi = require("hapi");
// Create a server with a host and port
const server = Hapi.server({
host: "localhost",
port: 8000
});
// Add the route
server.route({
method: "GET",
path: "/",
handler: (request, reply) => {
console.log(request.subdomains); // ['users', 'kiprosh']
console.log(request.subdomain); // 'users'
return "Home";
}
});
server.register({
plugin: subdomains,
options: {
// provide domain name for better results
domainName: "trackive.com",
// provide subdomains to exclude
// or an empty array
exclude: ["www", "api"]
}
});
// Start the server
async function start() {
try {
await server.start();
} catch (err) {
console.log(err);
process.exit(1);
}
console.log("Server running at:", server.info.uri);
}
start();
```
## CONTRIBUTING
Whether you are a novice or experienced software developer,
all contributions and suggestions are welcome!
1. Clone repo
```shell
git clone https://github.com/vemarav/subdomains.git
```
2. Add features or bug fixes
3. Make a Pull Request
OR
Report a bug [here](https://github.com/vemarav/subdomains/issues/new/choose)
Feel free to contribute, hosted on ❤️ with Github.
## LICENSE
Package published under [MIT License](https://github.com/vemarav/subdomains/blob/master/LICENSE)
## Author
- [Aravind Vemula](https://github.com/vemarav)
## SOCIAL
[](https://twitter.com/vemarav)