Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
subdomain routing support for express
JavaScript
branch: master

Merge pull request #7 from gabmontes/fixdep

Dependency on sequence fixed.
latest commit 34f6cc9702
@tblobaum authored
Failed to load latest commit information.
lib Added an option to change subdomains to different paths.
test Added an option to change subdomains to different paths.
.gitignore update readme, gitignore, license
.travis.yml added travis.yml, update readme, add mocha to deps
LICENSE update readme, gitignore, license
Makefile Fixed dev deps in package.json and updated Makefile and README.
README.md Merge pull request #5 from gabmontes/subdomaintonewbase
index.js moved to lib
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

Something went wrong with that request. Please try again.