subdomains

1.0.3 • Public • Published

subdomains

subdomains downloads npm codecov Build Status

This plugin supprots only Hapi

subdomains plugin adds subdomains & subdomain properties to request object

Usage

// 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

// 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

    git clone https://github.com/vemarav/subdomains.git
  2. Add features or bug fixes

  3. Make a Pull Request

    OR

    Report a bug here

Feel free to contribute, hosted on ❤️ with Github.

LICENSE

Package published under MIT License

Author

SOCIAL

Twitter Follow

Package Sidebar

Install

npm i subdomains

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

13.5 kB

Total Files

10

Last publish

Collaborators

  • vemarav