Added configuration section
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 0ace97c · Browse files · 10 files·+232 added−68 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+232 added−68 removed
- other:+232 added−68 removed
Provenance
- Commit
83d2555- Tree
6de1404- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
0ace97c
10 files changed+232 added−68 removed
modified:docs/layout/head.html-1 removed
55 unmodified lines56575859606061626398 unmodified lines55 unmodified lines color: white; text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }
h3 { margin-left: 20px; font-size: 18px; }
pre { margin: 20px 10px;98 unmodified linesmodified:docs/api.html+60 added-60 removed
620 unmodified lines621 </td>622 </tr>623 <tr class="code">624 <td class="docs">625-<p>Inherit from <code>connect.Server</code>.</p>625+<p>Inherit from <code>connect.Server</code>.</p> 626 </td>627 <td class="code">628 <pre><code><span class="variable">sys</span>.<span class="variable">inherits</span>(<span class="class">Server</span>, <span class="variable">connect</span>.<span class="class">Server</span>);</code></pre>629 </td>7 unmodified lines637 <ul>638 <li><p><strong>param</strong>: <em>Number</em> port</p></li>639 <li><p><strong>api</strong>: <em>public</em></p></li>640 </ul>641-641+642 </td>643 <td class="code">644 <pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">listen</span> = <span class="keyword">function</span>(<span class="variable">port</span>){645 <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'env'</span>, <span class="variable">process</span>.<span class="variable">env</span>.<span class="class">EXPRESS_ENV</span> || <span class="variable">process</span>.<span class="variable">connectEnv</span>.<span class="variable">name</span>);71 unmodified lines717 <li><p><strong>param</strong>: <em>String</em> setting</p></li>718 <li><p><strong>return</strong>: <em>Server</em> for chaining</p></li>719 <li><p><strong>api</strong>: <em>public</em></p></li>720 </ul>721-ZQ721+UQ722 </td>723 <td class="code">724 <pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">enable</span> = <span class="keyword">function</span>(<span class="variable">setting</span>){725 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">set</span>(<span class="variable">setting</span>, <span class="variable">true</span>);10 unmodified lines736 <li><p><strong>param</strong>: <em>String</em> setting</p></li>737 <li><p><strong>return</strong>: <em>Server</em> for chaining</p></li>738 <li><p><strong>api</strong>: <em>public</em></p></li>739 </ul>740-P740+Q741 </td>742 <td class="code">743 <pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">disable</span> = <span class="keyword">function</span>(<span class="variable">setting</span>){744 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">set</span>(<span class="variable">setting</span>, <span class="variable">false</span>);10 unmodified lines755 <li><p><strong>param</strong>: <em>String</em> setting</p></li>756 <li><p><strong>return</strong>: <em>Server</em> for chaining</p></li>757 <li><p><strong>api</strong>: <em>public</em></p></li>758 </ul>759-P759+Q760 </td>761 <td class="code">762 <pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">configure</span> = <span class="keyword">function</span>(<span class="variable">env</span>, <span class="variable">fn</span>){763 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">env</span> === <span class="string">'function'</span>) <span class="variable">fn</span> = <span class="variable">env</span>, <span class="variable">env</span> = <span class="string">'any'</span>;11 unmodified lines775 <span class="keyword">return</span> <span class="variable">arguments</span>.<span class="variable">callee</span>;776 })(<span class="string">'get'</span>)(<span class="string">'post'</span>)(<span class="string">'put'</span>)(<span class="string">'del'</span>);777 </code></pre>778 </td>779+</tr><tr class="filename"><td><h2 id="lib/express/utils.js">utils</h2></td><td>lib/express/utils.js</td></tr><tr class="code">780+<td class="docs">781+<p>Parse mini markdown implementation.782+The following conversions are supported,783+primarily for the “flash” middleware:</p>784+785+<p> <em>foo</em> or <em>foo</em> become <em>foo</em>786+ <strong>foo</strong> or <strong>foo</strong> become <strong>foo</strong>787+ <a href="B">A</a> becomes <a href="B">A</a></p>788+789+<h2></h2>790+791+<ul>792+<li><p><strong>param</strong>: <em>String</em> str</p></li>793+<li><p><strong>return</strong>: <em>String</em></p></li>794+<li><p><strong>api</strong>: <em>public</em></p></li>795+</ul>796+ 797+</td>798+<td class="code">799+<pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){800+ <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)801+ .<span class="variable">replace</span>(<span class="regexp">/(__|\*\*)(.*?)\1/g</span>, <span class="string">'<strong>$2</strong>'</span>)802+ .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'<em>$2</em>'</span>)803+ .<span class="variable">replace</span>(<span class="regexp">/\[([^\]]+)\]\(([^)]+)\)/g</span>, <span class="string">'<a href="$2">$1</a>'</span>);804+};</code></pre>805+</td>806+</tr>807+<tr class="code">808+<td class="docs">809+<p>Escape special characters in the given string of html.</p>810+811+<h2></h2>812+813+<ul>814+<li><p><strong>param</strong>: <em>String</em> html</p></li>815+<li><p><strong>return</strong>: <em>String</em></p></li>816+<li><p><strong>api</strong>: <em>public</em></p></li>817+</ul>818+819+</td>820+<td class="code">821+<pre><code><span class="variable">exports</span>.<span class="variable">htmlEscape</span> = <span class="keyword">function</span>(<span class="variable">html</span>) {822+ <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">html</span>)823+ .<span class="variable">replace</span>(<span class="regexp">/&/g</span>, <span class="string">'&'</span>)824+ .<span class="variable">replace</span>(<span class="regexp">/"/g</span>, <span class="string">'"'</span>)825+ .<span class="variable">replace</span>(<span class="regexp">/</g</span>, <span class="string">'<'</span>)826+ .<span class="variable">replace</span>(<span class="regexp">/>/g</span>, <span class="string">'>'</span>);827+};</code></pre>828+</td>829 </tr><tr class="filename"><td><h2 id="lib/express/view.js">view</h2></td><td>lib/express/view.js</td></tr><tr class="code">830 <td class="docs">831 <p>Module dependencies.</p>832 </td>27 unmodified lines860 861 <ul>862 <li><strong>type</strong>: <em>Object</em></li>863 </ul>814-864+865 </td>866 <td class="code">867 <pre><code><span class="keyword">var</span> <span class="variable">viewCache</span> = {};</code></pre>868 </td>4 unmodified lines873 874 <ul>875 <li><strong>api</strong>: <em>public</em></li>876 </ul>827-877+ 878 </td>879 <td class="code">880 <pre><code><span class="variable">exports</span>.<span class="variable">clearCache</span> = <span class="keyword">function</span>(){881 <span class="variable">viewCache</span> = {};6 unmodified lines888 889 <ul>890 <li><strong>type</strong>: <em>Object</em></li>891 </ul>842-892+ 893 </td>894 <td class="code">895 <pre><code><span class="keyword">var</span> <span class="variable">helpers</span> = <span class="variable">exports</span>.<span class="variable">helpers</span> = {};</code></pre>896 </td>25 unmodified lines922 <li><p><strong>param</strong>: <em>Object | Array</em> options or collection</p></li>923 <li><p><strong>return</strong>: <em>String</em></p></li>924 <li><p><strong>api</strong>: <em>public</em></p></li>925 </ul>876-ZQ926+\Q927 </td>928 <td class="code">929 <pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">partial</span> = <span class="keyword">function</span>(<span class="variable">view</span>, <span class="variable">options</span>, <span class="variable">ext</span>){930 <span class="keyword">if</span> (<span class="variable">ext</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">view</span>.<span class="variable">indexOf</span>(<span class="string">'.'</span>) &<span class="variable">lt</span>; <span class="number integer">0</span>) {57 unmodified lines988 <li><p><strong>param</strong>: <em>Object</em> options</p></li>989 <li><p><strong>param</strong>: <em>Function</em> fn</p></li>990 <li><p><strong>api</strong>: <em>public</em></p></li>991 </ul>942-992+�993 </td>994 <td class="code">995 <pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">render</span> = <span class="keyword">function</span>(<span class="variable">view</span>, <span class="variable">options</span>, <span class="variable">fn</span>){996 <span class="variable">options</span> = <span class="variable">options</span> || {};87 unmodified lines1084 }1085 };1086 </code></pre>1087 </td>1038-</tr><tr class="filename"><td><h2 id="lib/express/utils.js">utils</h2></td><td>lib/express/utils.js</td></tr><tr class="code">1039-<td class="docs">1040-<p>Parse mini markdown implementation.1041-The following conversions are supported,1042-primarily for the “flash” middleware:</p>1043-1044-<p> <em>foo</em> or <em>foo</em> become <em>foo</em>1045- <strong>foo</strong> or <strong>foo</strong> become <strong>foo</strong>1046- <a href="B">A</a> becomes <a href="B">A</a></p>1047-1048-<h2></h2>1049-1050-<ul>1051-<li><p><strong>param</strong>: <em>String</em> str</p></li>1052-<li><p><strong>return</strong>: <em>String</em></p></li>1053-<li><p><strong>api</strong>: <em>public</em></p></li>1054-</ul>1055-1056-</td>1057-<td class="code">1058-<pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){1059- <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)1060- .<span class="variable">replace</span>(<span class="regexp">/(__|\*\*)(.*?)\1/g</span>, <span class="string">'<strong>$2</strong>'</span>)1061- .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'<em>$2</em>'</span>)1062- .<span class="variable">replace</span>(<span class="regexp">/\[([^\]]+)\]\(([^)]+)\)/g</span>, <span class="string">'<a href="$2">$1</a>'</span>);1063-};</code></pre>1064-</td>1065-</tr>1066-<tr class="code">1067-<td class="docs">1068-<p>Escape special characters in the given string of html.</p>1069-1070-<h2></h2>1071-1072-<ul>1073-<li><p><strong>param</strong>: <em>String</em> html</p></li>1074-<li><p><strong>return</strong>: <em>String</em></p></li>1075-<li><p><strong>api</strong>: <em>public</em></p></li>1076-</ul>1077-1078-</td>1079-<td class="code">1080-<pre><code><span class="variable">exports</span>.<span class="variable">htmlEscape</span> = <span class="keyword">function</span>(<span class="variable">html</span>) {1081- <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">html</span>)1082- .<span class="variable">replace</span>(<span class="regexp">/&/g</span>, <span class="string">'&'</span>)1083- .<span class="variable">replace</span>(<span class="regexp">/"/g</span>, <span class="string">'"'</span>)1084- .<span class="variable">replace</span>(<span class="regexp">/</g</span>, <span class="string">'<'</span>)1085- .<span class="variable">replace</span>(<span class="regexp">/>/g</span>, <span class="string">'>'</span>);1086-};</code></pre>1087-</td>1088 </tr> </body>1089 </html></tbody></table>modified:docs/executable.html-1 removed
55 unmodified lines56 color: white;57 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }58 59 h3 {60- margin-left: 20px;60 font-size: 18px; }61 62 pre {63 margin: 20px 10px;121 unmodified linesmodified:docs/guide.1+66 added
1 unmodified line2 .\" http://github.com/rtomayko/ronn/3 .4 .TH "GUIDE" "" "July 2010" "" ""5 .6+.SS "First Application"7+The \fIexpress\.Server\fR now inherits from \fIhttp\.Server\fR, however follows the same idiom by providing \fIexpress\.createServer()\fR as shown below:8+.9+.IP "" 410+.11+.nf12+13+var app = require(\'express\')\.createServer();14+15+app\.get(\'/\', function(req, res){16+ res\.send(\'hello world\');17+});18+19+app\.listen(3000);20+.21+.fi22+.23+.IP "" 024+.25 .SS "Routing"26 Express utilizes the HTTP verbs to provide a meaningful, expressive routing API\. For example we may want to render a user\'s account for the path \fI/user/12\fR, this can be done by defining the route below\. The values associated to the named placeholders, are passed as the \fIthird\fR argument, which here we name \fIparams\fR\.27 .28 .IP "" 494 unmodified lines123 .124 .fi125 .126 .IP "" 0127+.128+.SS "Middleware"129+The Express \fIPlugin\fR is no more! middleware via Connect \fIhttp://github\.com/extjs/Connect\fR can be passed to \fIexpress\.createServer()\fR as you would with a regular Connect server\. For example:130+.131+.IP "" 4132+.133+.nf134 135+var connect = require(\'connect\'),136+ express = require(\'express\');137+138+var app = express\.createServer(139+ connect\.logger(),140+ connect\.redirect(),141+ connect\.bodyDecoder()142+);143+.144+.fi145+.146+.IP "" 0147+.148+.SS "Configuration"149+Express supports arbitrary environments, such as \fIproduction\fR and \fIdevelopment\fR\. Developers can use the \fIconfigure()\fR method to setup needs required by the current environment\. When \fIconfigure()\fR is called without an environment name it will be run in \fIevery\fR environment prior to the environment specific callback\.150+.151+.P152+In the example below we only \fIdumpExceptions\fR, and respond with exception stack traces in \fIdevelopment\fR mode, however for both environments we utilize \fImethodOverride\fR and \fIbodyDecoder\fR\.153+.154+.IP "" 4155+.156+.nf157+158+app\.configure(function(){159+ app\.use(\'/\', connect\.methodOverride());160+ app\.use(\'/\', connect\.bodyDecoder());161+});162+163+app\.configure(\'development\', function(){164+ app\.use(\'/\', connect\.errorHandler({ dumpExceptions: true, showStack: true }));165+});166+167+app\.configure(\'production\', function(){168+ app\.use(\'/\', connect\.errorHandler());169+});170+.171+.fi172+.173+.IP "" 0174+modified:docs/guide.html+53 added-1 removed
55 unmodified lines56 color: white;57 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }58 59 h3 {60- margin-left: 20px;60 font-size: 18px; }61 62 pre {63 margin: 20px 10px;95 unmodified lines159 <li><a href="guide.html">Guide</a></li>160 <li><a href="migrate.html">1.x Migration</a></li>161 </ul>162 <div class='mp'>163+<h3 id="First-Application">First Application</h3>164+165+<p>The <em>express.Server</em> now inherits from <em>http.Server</em>, however166+follows the same idiom by providing <em>express.createServer()</em> as shown below:</p>167+168+<pre><code>var app = require('express').createServer();169+170+app.get('/', function(req, res){171+ res.send('hello world');172+});173+174+app.listen(3000);175+</code></pre>176+177 <h3 id="Routing">Routing</h3>178 179 <p>Express utilizes the HTTP verbs to provide a meaningful, expressive routing API.180 For example we may want to render a user's account for the path <em>/user/12</em>, this65 unmodified lines246 // do something else247 });248 </code></pre>249 250+<h3 id="Middleware">Middleware</h3>251+252+<p>The Express <em>Plugin</em> is no more! middleware via <a href="http://github.com/extjs/Connect">Connect</a> can be253+passed to <em>express.createServer()</em> as you would with a regular Connect server. For example:</p>254+255+<pre><code>var connect = require('connect'),256+ express = require('express');257+258+var app = express.createServer(259+ connect.logger(),260+ connect.redirect(),261+ connect.bodyDecoder()262+);263+</code></pre>264+265+<h3 id="Configuration">Configuration</h3>266+267+<p>Express supports arbitrary environments, such as <em>production</em> and <em>development</em>. Developers268+can use the <em>configure()</em> method to setup needs required by the current environment. When269+<em>configure()</em> is called without an environment name it will be run in <em>every</em> environment270+prior to the environment specific callback.</p>271+272+<p>In the example below we only <em>dumpExceptions</em>, and respond with exception stack traces273+in <em>development</em> mode, however for both environments we utilize <em>methodOverride</em> and <em>bodyDecoder</em>.</p>274+275+<pre><code>app.configure(function(){276+ app.use('/', connect.methodOverride());277+ app.use('/', connect.bodyDecoder());278+});279+280+app.configure('development', function(){281+ app.use('/', connect.errorHandler({ dumpExceptions: true, showStack: true }));282+});283+284+app.configure('production', function(){285+ app.use('/', connect.errorHandler());286+});287+</code></pre>288+289 </div>290 </div>291 </div>292 </body>1 unmodified linemodified:docs/guide.md+50 added
1 2+### First Application3+4+The _express.Server_ now inherits from _http.Server_, however5+follows the same idiom by providing _express.createServer()_ as shown below:6+7+ var app = require('express').createServer();8+ 9+ app.get('/', function(req, res){10+ res.send('hello world');11+ });12+ 13+ app.listen(3000);14+15 ### Routing16 17 Express utilizes the HTTP verbs to provide a meaningful, expressive routing API.18 For example we may want to render a user's account for the path _/user/12_, this58 unmodified lines77 });78 79 app.get('/users', function(req, res, params){80 // do something else81+ });82+83+### Middleware84+85+The Express _Plugin_ is no more! middleware via [Connect](http://github.com/extjs/Connect) can be86+passed to _express.createServer()_ as you would with a regular Connect server. For example:87+88+ var connect = require('connect'),89+ express = require('express');90+91+ var app = express.createServer(92+ connect.logger(),93+ connect.redirect(),94+ connect.bodyDecoder()95+ );96+97+### Configuration98+99+Express supports arbitrary environments, such as _production_ and _development_. Developers100+can use the _configure()_ method to setup needs required by the current environment. When101+_configure()_ is called without an environment name it will be run in _every_ environment 102+prior to the environment specific callback.103+104+In the example below we only _dumpExceptions_, and respond with exception stack traces105+in _development_ mode, however for both environments we utilize _methodOverride_ and _bodyDecoder_.106+107+ app.configure(function(){108+ app.use('/', connect.methodOverride());109+ app.use('/', connect.bodyDecoder());110+ });111+ 112+ app.configure('development', function(){113+ app.use('/', connect.errorHandler({ dumpExceptions: true, showStack: true }));114+ });115+ 116+ app.configure('production', function(){117+ app.use('/', connect.errorHandler());118 });modified:docs/index.html-1 removed
55 unmodified lines56 color: white;57 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }58 59 h3 {60- margin-left: 20px;60 font-size: 18px; }61 62 pre {63 margin: 20px 10px;143 unmodified linesmodified:docs/migrate.1+1 added-1 removed
96 unmodified lines97 var app = express\.createServer();98 99 app\.use(\'/\', connect\.logger());100 app\.use(\'/\', connect\.methodOverride());101-app\.use(\'/\', connect\.cookie());101+app\.use(\'/\', connect\.cookieDecoder());102 .103 .fi104 .105 .IP "" 0225 unmodified linesmodified:docs/migrate.html+1 added-2 removed
55 unmodified lines56 color: white;57 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }58 59 h3 {60- margin-left: 20px;60 font-size: 18px; }61 62 pre {63 margin: 20px 10px;166 unmodified lines230 var app = express.createServer();231 232 app.use('/', connect.logger());233 app.use('/', connect.methodOverride());235-app.use('/', connect.cookie());234+app.use('/', connect.cookieDecoder());235 </code></pre>236 237 <p>For documentation on creating Connect middleware visit <a href="http://extjs.github.com/Connect/#Middleware-Authoring">Middleware Authoring</a>.</p>238 128 unmodified linesmodified:docs/migrate.md+1 added-1 removed
64 unmodified lines65 var app = express.createServer();66 67 app.use('/', connect.logger());68 app.use('/', connect.methodOverride());69- app.use('/', connect.cookie());69+ app.use('/', connect.cookieDecoder());70 71 For documentation on creating Connect middleware visit [Middleware Authoring](http://extjs.github.com/Connect/#Middleware-Authoring).72 73 ### Running Applications106 unmodified lines