1 | buffet
|
2 | ======
|
3 |
|
4 | Performance-oriented static file server
|
5 |
|
6 | [![build status](https://secure.travis-ci.org/carlos8f/node-buffet.png)](http://travis-ci.org/carlos8f/node-buffet)
|
7 |
|
8 | Idea
|
9 | ----
|
10 |
|
11 | Serving static files should be the most efficient thing that a Node.js app can
|
12 | do. Turns out, runtime syscalls to the filesystem can really hang your page
|
13 | loads, especially if your filesystem is networked or unreliable in some other way.
|
14 |
|
15 | Buffet takes a fully-bufferred approach -- all files are fully loaded into
|
16 | memory when your app boots, so you will never feel the burn of the filesystem.
|
17 | In practice, this is immensely efficient. So much so that putting
|
18 | [Varnish](https://www.varnish-cache.org/) in front of your app might even make it
|
19 | slower! Well, almost (summary from buffet's `make bench`):
|
20 |
|
21 | ```
|
22 | **************** varnish (5876.03 rps)
|
23 | **************** buffet-server (5587.53 rps)
|
24 | ************** buffet (5008.57 rps)
|
25 | ********** node-static (3643.76 rps)
|
26 | ****** send (2130.13 rps)
|
27 | ***** ecstatic (1690.86 rps)
|
28 | *** paperboy (737.16 rps)
|
29 | ```
|
30 |
|
31 | Continuous deployment is also becoming all the rage, and restarting Varnish is
|
32 | a pain, so consider using Buffet -- your pages will always be fresh and zesty!
|
33 |
|
34 | Usage
|
35 | -----
|
36 |
|
37 | ### Middleware
|
38 |
|
39 | Middleware version (compatible with [connect](http://www.senchalabs.org/connect/),
|
40 | [union/flatiron](http://flatironjs.org/), [middler](https://npmjs.org/package/middler), etc.)
|
41 |
|
42 | ```javascript
|
43 | var connect = require('connect')
|
44 | , app = connect()
|
45 | , buffet = require('buffet')() // root defaults to ./public
|
46 |
|
47 | app.use(buffet);
|
48 | app.use(buffet.notFound);
|
49 |
|
50 | var server = require('http').createServer(app);
|
51 | server.listen(3000, function () {
|
52 | console.log('test server running on port 3000');
|
53 | });
|
54 | ```
|
55 |
|
56 | ### Easy built-in server
|
57 |
|
58 | ```bash
|
59 | $ npm install -g buffet
|
60 | $ cd /var/www/html && buffet
|
61 | buffet 0.4.0 listening on port 8080
|
62 | ```
|
63 |
|
64 | ### As a request handler
|
65 |
|
66 | ```javascript
|
67 | var server = require('http').createServer();
|
68 | var buffet = require('buffet')(); // root defaults to ./public
|
69 |
|
70 | server.on('request', buffet);
|
71 | server.on('request', buffet.notFound);
|
72 |
|
73 | server.listen(3000, function () {
|
74 | console.log('test server running on port 3000');
|
75 | });
|
76 | ```
|
77 |
|
78 | Options
|
79 | -------
|
80 |
|
81 | - `root`: Document root. Can also be passed as the first parameter to `buffet()`.
|
82 | (Default: `./public`)
|
83 | - `indexes`: True to look for `options.index` and serve it for directory requests.
|
84 | (Default: true)
|
85 | - `index`: Name of index file to look for. (Default: `index.html`)
|
86 | - `gzip`: True to enable gzip when clients can accept it. (Default: `true`)
|
87 | - `watch`: True to auto-update the buffer when files change. (Default: `true`)
|
88 | - `poweredBy`: True to add the `X-Powered-By` header. (Default: `true`)
|
89 | - `maxAge`: Number of max-age seconds to set `Cache-Control` header. Set to
|
90 | `false` or `0` to disable. (Default: `300`)
|
91 | - `notFoundPath`: Path to be rendered on `buffetMiddleware.notFound`. (Default:
|
92 | `/404.html`)
|
93 | - `keepAlive`: Timeout (in milliseconds) for HTTP keep-alive. (Default: `5000`)
|
94 |
|
95 | Running your own benchmark
|
96 | --------------------------
|
97 |
|
98 | Type `make bench` in the buffet directory (you'll need
|
99 | [siege](http://www.joedog.org/siege-home/) installed).
|
100 |
|
101 | Brought to you by [benchmarx](https://github.com/carlos8f/node-benchmarx).
|
102 |
|
103 | See [here](https://gist.github.com/3473500) for my results.
|
104 |
|
105 | - - -
|
106 |
|
107 | ### Developed by [Terra Eclipse](http://www.terraeclipse.com)
|
108 | Terra Eclipse, Inc. is a nationally recognized political technology and
|
109 | strategy firm located in Aptos, CA and Washington, D.C.
|
110 |
|
111 | - - -
|
112 |
|
113 | ### License: MIT
|
114 |
|
115 | - Copyright (C) 2012 Carlos Rodriguez (http://s8f.org/)
|
116 | - Copyright (C) 2012 Terra Eclipse, Inc. (http://www.terraeclipse.com/)
|
117 |
|
118 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
119 | of this software and associated documentation files (the "Software"), to deal
|
120 | in the Software without restriction, including without limitation the rights
|
121 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
122 | copies of the Software, and to permit persons to whom the Software is furnished
|
123 | to do so, subject to the following conditions:
|
124 |
|
125 | The above copyright notice and this permission notice shall be included in
|
126 | all copies or substantial portions of the Software.
|
127 |
|
128 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
129 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
130 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
131 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
132 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
133 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
134 | SOFTWARE. |
\ | No newline at end of file |