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 (4874.64 rps)
|
23 | *************** buffet-server (4421.13 rps)
|
24 | ************* buffet (3742.6 rps)
|
25 | ********* st (2659.29 rps)
|
26 | ********* node-static (2645.31 rps)
|
27 | ****** send (1646.75 rps)
|
28 | ***** ecstatic (1302.24 rps)
|
29 | *** paperboy (625.28 rps)
|
30 | ```
|
31 |
|
32 | Continuous deployment is also becoming all the rage, and restarting Varnish is
|
33 | a pain, so consider using Buffet -- your pages will always be fresh and zesty!
|
34 |
|
35 | Usage
|
36 | -----
|
37 |
|
38 | ### Middleware
|
39 |
|
40 | Middleware version (compatible with [connect](http://www.senchalabs.org/connect/),
|
41 | [union/flatiron](http://flatironjs.org/), [middler](https://npmjs.org/package/middler), etc.)
|
42 |
|
43 | ```javascript
|
44 | var connect = require('connect')
|
45 | , app = connect()
|
46 | , buffet = require('buffet')({root: './public'}) // root defaults to ./public
|
47 |
|
48 | app.use(buffet);
|
49 | app.use(buffet.notFound);
|
50 |
|
51 | var server = require('http').createServer(app);
|
52 | server.listen(3000, function () {
|
53 | console.log('test server running on port 3000');
|
54 | });
|
55 | ```
|
56 |
|
57 | ### Easy built-in server
|
58 |
|
59 | ```bash
|
60 | $ npm install -g buffet
|
61 | $ cd /var/www/html && buffet
|
62 | buffet 0.4.0 listening on port 8080
|
63 | ```
|
64 |
|
65 | ### As a request handler
|
66 |
|
67 | ```javascript
|
68 | var server = require('http').createServer();
|
69 | var buffet = require('buffet')(); // root defaults to ./public
|
70 |
|
71 | server.on('request', function (req, res) {
|
72 | buffet(req, res, function () {
|
73 | buffet.notFound(req, res);
|
74 | });
|
75 | });
|
76 |
|
77 | server.listen(3000, function () {
|
78 | console.log('test server running on port 3000');
|
79 | });
|
80 | ```
|
81 |
|
82 | Options
|
83 | -------
|
84 |
|
85 | - `root`: Document root. Can also be passed as the first parameter to `buffet()`.
|
86 | (Default: `./public`)
|
87 | - `indexes`: True to look for `options.index` and serve it for directory requests.
|
88 | (Default: true)
|
89 | - `index`: Name of index file to look for. (Default: `index.html`)
|
90 | - `gzip`: True to enable gzip when clients can accept it. (Default: `true`)
|
91 | - `watch`: True to auto-update the buffer when files change. (Default: `true`)
|
92 | - `poweredBy`: True to add the `X-Powered-By` header. (Default: `true`)
|
93 | - `maxAge`: Number of max-age seconds to set `Cache-Control` header. Set to
|
94 | `false` or `0` to disable. (Default: `300`)
|
95 | - `notFoundPath`: Path to be rendered on `buffetMiddleware.notFound`. (Default:
|
96 | `/404.html`)
|
97 | - `keepAlive`: Timeout (in milliseconds) for HTTP keep-alive. (Default: `5000`)
|
98 | - `defaultContentType`: If the file does not have an extension, set this to specify the default `Content-Type` sent to the browser. This defaults to `application/octet-stream`.
|
99 |
|
100 | Running your own benchmark
|
101 | --------------------------
|
102 |
|
103 | Type `make bench` in the buffet directory (you'll need
|
104 | [siege](http://www.joedog.org/siege-home/) installed).
|
105 |
|
106 | Brought to you by [benchmarx](https://github.com/carlos8f/node-benchmarx).
|
107 |
|
108 | See [here](https://gist.github.com/3473500) for my results.
|
109 |
|
110 | - - -
|
111 |
|
112 | ### Developed by [Terra Eclipse](http://www.terraeclipse.com)
|
113 | Terra Eclipse, Inc. is a nationally recognized political technology and
|
114 | strategy firm located in Aptos, CA and Washington, D.C.
|
115 |
|
116 | - - -
|
117 |
|
118 | ### License: MIT
|
119 |
|
120 | - Copyright (C) 2012 Carlos Rodriguez (http://s8f.org/)
|
121 | - Copyright (C) 2012 Terra Eclipse, Inc. (http://www.terraeclipse.com/)
|
122 |
|
123 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
124 | of this software and associated documentation files (the "Software"), to deal
|
125 | in the Software without restriction, including without limitation the rights
|
126 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
127 | copies of the Software, and to permit persons to whom the Software is furnished
|
128 | to do so, subject to the following conditions:
|
129 |
|
130 | The above copyright notice and this permission notice shall be included in
|
131 | all copies or substantial portions of the Software.
|
132 |
|
133 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
134 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
135 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
136 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
137 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
138 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
139 | SOFTWARE. |
\ | No newline at end of file |