Skip to content
Myr

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

10 files+232 added−68 removed

modified:docs/layout/head.html-1 removed
modified:docs/api.html+60 added-60 removed
620 unmodified lines
621</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 lines
637<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>641641642</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 lines
717<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>721ZQ721UQ722</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 lines
736<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>740P740Q741</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 lines
755<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>759P759Q760</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 lines
775 <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.782The following conversions are supported,783primarily for the &ldquo;flash&rdquo; middleware:</p>784785<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>788789<h2></h2>790791<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">'&lt;strong&gt;$2&lt;/strong&gt;'</span>)802 .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'&lt;em&gt;$2&lt;/em&gt;'</span>)803 .<span class="variable">replace</span>(<span class="regexp">/\[([^\]]+)\]\(([^)]+)\)/g</span>, <span class="string">'&lt;a href=&quot;$2&quot;&gt;$1&lt;/a&gt;'</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>810811<h2></h2>812813<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>818819</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">/&amp;/g</span>, <span class="string">'&amp;'</span>)824 .<span class="variable">replace</span>(<span class="regexp">/&quot;/g</span>, <span class="string">'&quot;'</span>)825 .<span class="variable">replace</span>(<span class="regexp">/&lt;/g</span>, <span class="string">'&lt;'</span>)826 .<span class="variable">replace</span>(<span class="regexp">/&gt;/g</span>, <span class="string">'&gt;'</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 lines
860861<ul>862<li><strong>type</strong>: <em>Object</em></li>863</ul>814864865</td>866<td class="code">867<pre><code><span class="keyword">var</span> <span class="variable">viewCache</span> = {};</code></pre>868</td>
4 unmodified lines
873874<ul>875<li><strong>api</strong>: <em>public</em></li>876</ul>827877 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 lines
888889<ul>890<li><strong>type</strong>: <em>Object</em></li>891</ul>842892 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 lines
922<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>876ZQ926\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 lines
988<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>942992�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 lines
1084 }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.1041The following conversions are supported,1042primarily for the &ldquo;flash&rdquo; middleware:</p>10431044<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>10471048<h2></h2>10491050<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>10551056</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">'&lt;strong&gt;$2&lt;/strong&gt;'</span>)1061 .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'&lt;em&gt;$2&lt;/em&gt;'</span>)1062 .<span class="variable">replace</span>(<span class="regexp">/\[([^\]]+)\]\(([^)]+)\)/g</span>, <span class="string">'&lt;a href=&quot;$2&quot;&gt;$1&lt;/a&gt;'</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>10691070<h2></h2>10711072<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>10771078</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">/&amp;/g</span>, <span class="string">'&amp;'</span>)1083 .<span class="variable">replace</span>(<span class="regexp">/&quot;/g</span>, <span class="string">'&quot;'</span>)1084 .<span class="variable">replace</span>(<span class="regexp">/&lt;/g</span>, <span class="string">'&lt;'</span>)1085 .<span class="variable">replace</span>(<span class="regexp">/&gt;/g</span>, <span class="string">'&gt;'</span>);1086};</code></pre>1087</td>1088</tr> </body>1089</html></tbody></table>
modified:docs/executable.html-1 removed
55 unmodified lines
56 color: white;57 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }5859 h3 {60 margin-left: 20px;60 font-size: 18px; }6162 pre {63 margin: 20px 10px;
121 unmodified lines
modified:docs/guide.1+66 added
1 unmodified line
2.\" http://github.com/rtomayko/ronn/3.4.TH "GUIDE" "" "July 2010" "" ""5.6.SS "First Application"7The \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.nf1213var app = require(\'express\')\.createServer();1415app\.get(\'/\', function(req, res){16 res\.send(\'hello world\');17});1819app\.listen(3000);20.21.fi22.23.IP "" 024.25.SS "Routing"26Express 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 "" 4
94 unmodified lines
123.124.fi125.126.IP "" 0127.128.SS "Middleware"129The 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.nf134135var connect = require(\'connect\'),136 express = require(\'express\');137138var app = express\.createServer(139 connect\.logger(),140 connect\.redirect(),141 connect\.bodyDecoder()142);143.144.fi145.146.IP "" 0147.148.SS "Configuration"149Express 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.P152In 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.nf157158app\.configure(function(){159 app\.use(\'/\', connect\.methodOverride());160 app\.use(\'/\', connect\.bodyDecoder());161});162163app\.configure(\'development\', function(){164 app\.use(\'/\', connect\.errorHandler({ dumpExceptions: true, showStack: true }));165});166167app\.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 lines
56 color: white;57 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }5859 h3 {60 margin-left: 20px;60 font-size: 18px; }6162 pre {63 margin: 20px 10px;
95 unmodified lines
159 <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>164165<p>The <em>express.Server</em> now inherits from <em>http.Server</em>, however166follows the same idiom by providing <em>express.createServer()</em> as shown below:</p>167168<pre><code>var app = require('express').createServer();169170app.get('/', function(req, res){171 res.send('hello world');172});173174app.listen(3000);175</code></pre>176177<h3 id="Routing">Routing</h3>178179<p>Express utilizes the HTTP verbs to provide a meaningful, expressive routing API.180For example we may want to render a user's account for the path <em>/user/12</em>, this
65 unmodified lines
246 // do something else247});248</code></pre>249250<h3 id="Middleware">Middleware</h3>251252<p>The Express <em>Plugin</em> is no more! middleware via <a href="http://github.com/extjs/Connect">Connect</a> can be253passed to <em>express.createServer()</em> as you would with a regular Connect server. For example:</p>254255<pre><code>var connect = require('connect'),256 express = require('express');257258var app = express.createServer(259 connect.logger(),260 connect.redirect(),261 connect.bodyDecoder()262);263</code></pre>264265<h3 id="Configuration">Configuration</h3>266267<p>Express supports arbitrary environments, such as <em>production</em> and <em>development</em>. Developers268can 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> environment270prior to the environment specific callback.</p>271272<p>In the example below we only <em>dumpExceptions</em>, and respond with exception stack traces273in <em>development</em> mode, however for both environments we utilize <em>methodOverride</em> and <em>bodyDecoder</em>.</p>274275<pre><code>app.configure(function(){276 app.use('/', connect.methodOverride());277 app.use('/', connect.bodyDecoder());278});279280app.configure('development', function(){281 app.use('/', connect.errorHandler({ dumpExceptions: true, showStack: true }));282});283284app.configure('production', function(){285 app.use('/', connect.errorHandler());286});287</code></pre>288289</div>290 </div>291 </div>292 </body>
1 unmodified line
modified:docs/guide.md+50 added
12### First Application34The _express.Server_ now inherits from _http.Server_, however5follows the same idiom by providing _express.createServer()_ as shown below:67 var app = require('express').createServer();8 9 app.get('/', function(req, res){10 res.send('hello world');11 });12 13 app.listen(3000);1415### Routing1617Express utilizes the HTTP verbs to provide a meaningful, expressive routing API.18For example we may want to render a user's account for the path _/user/12_, this
58 unmodified lines
77 });78 79 app.get('/users', function(req, res, params){80 // do something else81 });8283### Middleware8485The Express _Plugin_ is no more! middleware via [Connect](http://github.com/extjs/Connect) can be86passed to _express.createServer()_ as you would with a regular Connect server. For example:8788 var connect = require('connect'),89 express = require('express');9091 var app = express.createServer(92 connect.logger(),93 connect.redirect(),94 connect.bodyDecoder()95 );9697### Configuration9899Express supports arbitrary environments, such as _production_ and _development_. Developers100can 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 102prior to the environment specific callback.103104In the example below we only _dumpExceptions_, and respond with exception stack traces105in _development_ mode, however for both environments we utilize _methodOverride_ and _bodyDecoder_.106107 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 lines
56 color: white;57 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }5859 h3 {60 margin-left: 20px;60 font-size: 18px; }6162 pre {63 margin: 20px 10px;
143 unmodified lines
modified:docs/migrate.1+1 added-1 removed
96 unmodified lines
97var app = express\.createServer();9899app\.use(\'/\', connect\.logger());100app\.use(\'/\', connect\.methodOverride());101app\.use(\'/\', connect\.cookie());101app\.use(\'/\', connect\.cookieDecoder());102.103.fi104.105.IP "" 0
225 unmodified lines
modified:docs/migrate.html+1 added-2 removed
55 unmodified lines
56 color: white;57 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }5859 h3 {60 margin-left: 20px;60 font-size: 18px; }6162 pre {63 margin: 20px 10px;
166 unmodified lines
230var app = express.createServer();231232app.use('/', connect.logger());233app.use('/', connect.methodOverride());235app.use('/', connect.cookie());234app.use('/', connect.cookieDecoder());235</code></pre>236237<p>For documentation on creating Connect middleware visit <a href="http://extjs.github.com/Connect/#Middleware-Authoring">Middleware Authoring</a>.</p>238
128 unmodified lines
modified:docs/migrate.md+1 added-1 removed
64 unmodified lines
65 var app = express.createServer();6667 app.use('/', connect.logger());68 app.use('/', connect.methodOverride());69 app.use('/', connect.cookie());69 app.use('/', connect.cookieDecoder());7071For documentation on creating Connect middleware visit [Middleware Authoring](http://extjs.github.com/Connect/#Middleware-Authoring).7273### Running Applications
106 unmodified lines