UNPKG

863 BJavaScriptView Raw
1
2/*!
3 * Connect - vhost
4 * Copyright(c) 2010 Sencha Inc.
5 * Copyright(c) 2011 TJ Holowaychuk
6 * MIT Licensed
7 */
8
9/**
10 * Module dependencies.
11 */
12
13var vhost = require('vhost');
14
15/**
16 * Vhost:
17 *
18 * See [vhost](https://github.com/expressjs/vhost)
19 *
20 * @param {String} hostname
21 * @param {Server} server
22 * @return {Function}
23 * @api public
24 */
25
26module.exports = function(hostname, server) {
27 if (typeof hostname === 'string') {
28 // back-compat
29 hostname = new RegExp('^' + hostname.replace(/[^*\w]/g, '\\$&').replace(/[*]/g, '(?:.*?)') + '$', 'i');
30 }
31
32 if (typeof server !== 'function' && typeof server.emit === 'function') {
33 // back-compat
34 server = createEmitRequest(server);
35 }
36
37 return vhost(hostname, server);
38};
39
40function createEmitRequest(server) {
41 return function emitRequest(req, res) {
42 server.emit('request', req, res);
43 };
44}