Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moved to lib

  • Loading branch information...
commit 54dae9ef072f3f71d4dca21a0d9d48fbf31a0572 1 parent 5095d10
@tblobaum authored
Showing with 52 additions and 50 deletions.
  1. +1 −50 index.js
  2. +51 −0 lib/subdomains.js
View
51 index.js
@@ -1,51 +1,2 @@
-
-/*!
- * express-subdomains
- * Copyright(c) Thomas Blobaum
- * MIT Licensed
- */
-
-var subs = [{base:'.'}]
-var Sequence = require('sequence');
-
-module.exports = {
- use: function (base, options) {
- options = options || {}
- subs.unshift({
- base:base,
- options:options
- })
- return this
- },
- middleware: function (req, res, next) {
-
- forEachAsync(subs, function(fn, item, i, arr) {
-
- if (RegExp(item.base, "gi").test(req.headers.host)) {
- if (item.base !== '.') req.url = '/' + item.base + req.url
- next()
- }
-
- else {
- fn()
- }
-
- })
-
- }
-}
-
-function forEachAsync (arr, callback) {
- var sequence = Sequence()
-
- function handleItem(item, i, arr) {
- sequence.then(function (next) {
- callback(next, item, i, arr)
- })
- }
-
- arr.forEach(handleItem)
-
- return sequence
-}
+module.exports = require('./lib/subdomains')
View
51 lib/subdomains.js
@@ -0,0 +1,51 @@
+
+/*!
+ * express-subdomains
+ * Copyright(c) Thomas Blobaum
+ * MIT Licensed
+ */
+
+var subs = [{base:'.'}]
+var Sequence = require('sequence');
+
+module.exports = {
+ use: function (base, options) {
+ options = options || {}
+ subs.unshift({
+ base:base,
+ options:options
+ })
+ return this
+ },
+ middleware: function (req, res, next) {
+
+ forEachAsync(subs, function(fn, item, i, arr) {
+
+ if (RegExp(item.base, "gi").test(req.headers.host)) {
+ if (item.base !== '.') req.url = '/' + item.base + req.url
+ next()
+ }
+
+ else {
+ fn()
+ }
+
+ })
+
+ }
+}
+
+function forEachAsync (arr, callback) {
+ var sequence = Sequence()
+
+ function handleItem(item, i, arr) {
+ sequence.then(function (next) {
+ callback(next, item, i, arr)
+ })
+ }
+
+ arr.forEach(handleItem)
+
+ return sequence
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.