Giter VIP home page Giter VIP logo

wildcard-subdomains's Introduction

wildcard-subdomains

Build Status npm version

Handle dynamic/wildcard subdomains in Express.js. Perfect for when you have customized subdomains for different users, and need to handle them within your Node app.

Requests to foo.yourdomain.com can be handled with using the route /_sub/:subdomain

Paths and query strings and paths remain intact. For example:

foo.yourdomain.com/post/cat?oh=hai can be handled with using the route /_sub/foo/post/cat?oh=hai

Dependency free!

How to use

Require the module in app.js:

var wildcardSubdomains = require('wildcard-subdomains')

Use the module in middleware:

app.use(wildcardSubdomains(opts))

opts - Object

Key Type Default Description
namespace String '_sub' Prepended to the path
whitelist String or Array ['www'] Subdomains to ignore

Example options:

app.use(wildcardSubdomains({
  namespace: 's',
  whitelist: ['www', 'app'],
}))

Handle the new route for your subdomain, for example foo.yourdomain.com would be handled with:

app.get('/s/foo/', function(req, res){
  res.send("Meow!")
})

By using the whiteList option, requests to app.yourdomain.com and www.yourdomain.com will be ignored and handled normally.

Example

npm run example

Or check the examples directory in this repo

Protip

For testing subdomains locally, use the domain vcap.me:3000

This is a domain that points back to your localhost, allowing you to test subdomains like foobar.vcap.me

Running your app behind a proxy? You'll likely need to set the appropriate trust proxy in express

wildcard-subdomains's People

Contributors

patmood avatar bendyorke avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.