subdomain routing support for express
JavaScript
Latest commit 34f6cc9 Apr 12, 2013 @tblobaum Merge pull request #7 from gabmontes/fixdep
Dependency on sequence fixed.
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
LICENSE
Makefile
README.md
index.js
package.json

README.md

express-subdomains

Build Status

Subdomains are placed at the beginning of a route by default.

Basic example

var subdomains = require('express-subdomains')
    , express = require('express')
    , app = Express.createServer();

// example: api.example.com/user -> '/api/user'

subdomains
  .use('api')
  .use('other.vanity.domain');

// Place this line before
// app.use(app.router)
app.use(subdomains.middleware);

// Path for domain/api/user and api.domain/user
app.get('/api/user' function (req, res, next) {
  // ..
})

app.listen();

API

domain(url)

Set the domain url to be used in all the following calls to use. Can be set to "" to match any domains.

use(base, options)

Set a subdomain as base. If domain is set, it will be added to the subdomian to form a full host url.

The valid options are:

newbase when set, this value will be used instead of base to rewrite the url path.

strict()

By default, subdomains will not change the url when no rules match. If only defined subdomain+domain matches are required, strict shall be called.

Testing locally

Add the following line(s) to your /etc/hosts file

127.0.0.1   api.localhost
127.0.0.1   other.vanity.domain.localhost

Tests

npm install and npm test

Install

npm install express-subdomains

License

MIT