Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including hapi-subdomain with all npm packages installed. Try it out:

var hapiSubdomain = require("hapi-subdomain")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

hapi-subdomain v1.0.0

Simple subdomain routing tool for Hapi.js

Hapi-subdomain

This is a simple plugin for using subdomains with Hapi.js, as is typical in multi-tenant applications. For example, if you give each user their own profile page at username.example.com, this plugin can invisibly redirect those urls to example.com/users/username, making configuring your routes much easier.

Once the plugin is installed, it gets added to your:

server.register([{
  register: require('hapi-subdomain'),
  options: {
    exclude: ['www', 'api', 'mail'],
    destination: '/tenant'
  }
  }], function(err) {
    if (err) console.log(err)
    });

exclude is an array of subdomains to ignore. destination is the path to prepend the subdomain to.

Only the first subdomain is detected by the regex, and any route with no subdomain (http://example.com) is ignored.

Feedback and pull requests happily accepted.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free