summaryrefslogtreecommitdiffstats
path: root/vnfmarket/src/main/webapp/vnfmarket/node_modules/connect/lib/middleware/vhost.js
blob: c5b7d9ebd6228d40d93141e4a5dbe1447f55eafb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*!
 * Connect - vhost
 * Copyright(c) 2010 Sencha Inc.
 * Copyright(c) 2011 TJ Holowaychuk
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var vhost = require('vhost');

/**
 * Vhost:
 *
 * See [vhost](https://github.com/expressjs/vhost)
 *
 * @param {String} hostname
 * @param {Server} server
 * @return {Function}
 * @api public
 */

module.exports = function(hostname, server) {
  if (typeof hostname === 'string') {
    // back-compat
    hostname = new RegExp('^' + hostname.replace(/[^*\w]/g, '\\$&').replace(/[*]/g, '(?:.*?)')  + '$', 'i');
  }

  if (typeof server !== 'function' && typeof server.emit === 'function') {
    // back-compat
    server = createEmitRequest(server);
  }

  return vhost(hostname, server);
};

function createEmitRequest(server) {
  return function emitRequest(req, res) {
    server.emit('request', req, res);
  };
}