1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | var vhost = require('vhost');
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | module.exports = function(hostname, server) {
|
27 | if (typeof hostname === 'string') {
|
28 |
|
29 | hostname = new RegExp('^' + hostname.replace(/[^*\w]/g, '\\$&').replace(/[*]/g, '(?:.*?)') + '$', 'i');
|
30 | }
|
31 |
|
32 | if (typeof server !== 'function' && typeof server.emit === 'function') {
|
33 |
|
34 | server = createEmitRequest(server);
|
35 | }
|
36 |
|
37 | return vhost(hostname, server);
|
38 | };
|
39 |
|
40 | function createEmitRequest(server) {
|
41 | return function emitRequest(req, res) {
|
42 | server.emit('request', req, res);
|
43 | };
|
44 | }
|