Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / vhost / README.md
1 # vhost
2
3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Build Status][travis-image]][travis-url]
6 [![Test Coverage][coveralls-image]][coveralls-url]
7 [![Gratipay][gratipay-image]][gratipay-url]
8
9 ## Install
10
11 ```sh
12 $ npm install vhost
13 ```
14
15 ## API
16
17 ```js
18 var vhost = require('vhost')
19 ```
20
21 ### vhost(hostname, handle)
22
23 Create a new middleware function to hand off request to `handle` when the incoming
24 host for the request matches `hostname`. The function is called as
25 `handle(req, res, next)`, like a standard middleware.
26
27 `hostname` can be a string or a RegExp object. When `hostname` is a string it can
28 contain `*` to match 1 or more characters in that section of the hostname. When
29 `hostname` is a RegExp, it will be forced to case-insensitive (since hostnames are)
30 and will be forced to match based on the start and end of the hostname.
31
32 When host is matched and the request is sent down to a vhost handler, the `req.vhost`
33 property will be populated with an object. This object will have numeric properties
34 corresponding to each wildcard (or capture group if RegExp object provided) and the
35 `hostname` that was matched.
36
37 ```js
38 // for match of "foo.bar.example.com:8080" against "*.*.example.com":
39 req.vhost.host === 'foo.bar.example.com:8080'
40 req.vhost.hostname === 'foo.bar.example.com'
41 req.vhost.length === 2
42 req.vhost[0] === 'foo'
43 req.vhost[1] === 'bar'
44 ```
45
46 ## Examples
47
48 ### using with connect for static serving
49
50 ```js
51 var connect = require('connect')
52 var serveStatic = require('serve-static')
53 var vhost = require('vhost')
54
55 var mailapp = connect()
56
57 // add middlewares to mailapp for mail.example.com
58
59 // create app to serve static files on subdomain
60 var staticapp = connect()
61 staticapp.use(serveStatic('public'))
62
63 // create main app
64 var app = connect()
65
66 // add vhost routing to main app for mail
67 app.use(vhost('mail.example.com', mailapp))
68
69 // route static assets for "assets-*" subdomain to get
70 // around max host connections limit on browsers
71 app.use(vhost('assets-*.example.com', staticapp))
72
73 // add middlewares and main usage to app
74
75 app.listen(3000)
76 ```
77
78 ### using with connect for user subdomains
79
80 ```js
81 var connect = require('connect')
82 var serveStatic = require('serve-static')
83 var vhost = require('vhost')
84
85 var mainapp = connect()
86
87 // add middlewares to mainapp for the main web site
88
89 // create app that will server user content from public/{username}/
90 var userapp = connect()
91
92 userapp.use(function(req, res, next){
93   var username = req.vhost[0] // username is the "*"
94
95   // pretend request was for /{username}/* for file serving
96   req.originalUrl = req.url
97   req.url = '/' + username + req.url
98
99   next()
100 })
101 userapp.use(serveStatic('public'))
102
103 // create main app
104 var app = connect()
105
106 // add vhost routing for main app
107 app.use(vhost('userpages.local', mainapp))
108 app.use(vhost('www.userpages.local', mainapp))
109
110 // listen on all subdomains for user pages
111 app.use(vhost('*.userpages.local', userapp))
112
113 app.listen(3000)
114 ```
115
116 ### using with any generic request handler
117
118 ```js
119 var connect = require('connect')
120 var http = require('http')
121 var vhost = require('vhost')
122
123 // create main app
124 var app = connect()
125
126 app.use(vhost('mail.example.com', function (req, res) {
127   // handle req + res belonging to mail.example.com
128   res.setHeader('Content-Type', 'text/plain')
129   res.end('hello from mail!')
130 }))
131
132 // an external api server in any framework
133 var httpServer = http.createServer(function (req, res) {
134   res.setHeader('Content-Type', 'text/plain')
135   res.end('hello from the api!')
136 })
137
138 app.use(vhost('api.example.com', function (req, res) {
139   // handle req + res belonging to api.example.com
140   // pass the request to a standard Node.js HTTP server
141   httpServer.emit('request', req, res)
142 }))
143
144 app.listen(3000)
145 ```
146
147 ## License
148
149 [MIT](LICENSE)
150
151 [npm-image]: https://img.shields.io/npm/v/vhost.svg
152 [npm-url]: https://npmjs.org/package/vhost
153 [travis-image]: https://img.shields.io/travis/expressjs/vhost/master.svg
154 [travis-url]: https://travis-ci.org/expressjs/vhost
155 [coveralls-image]: https://img.shields.io/coveralls/expressjs/vhost/master.svg
156 [coveralls-url]: https://coveralls.io/r/expressjs/vhost
157 [downloads-image]: https://img.shields.io/npm/dm/vhost.svg
158 [downloads-url]: https://npmjs.org/package/vhost
159 [gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg
160 [gratipay-url]: https://gratipay.com/dougwilson/