Rebuilt docs
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 5297966 · Browse files · 4 files·+133 added−21 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+133 added−21 removed
- other:+133 added−21 removed
Provenance
- Commit
ba88e48- Tree
6fcb79d- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
5297966
4 files changed+133 added−21 removed
modified:docs/api.html+79 added-16 removed
611 unmodified lines612 <span class="this">this</span>.<span class="variable">viewHelpers</span> = {};613 <span class="this">this</span>.<span class="variable">dynamicViewHelpers</span> = {};614 <span class="variable">connect</span>.<span class="class">Server</span>.<span class="variable">call</span>(<span class="this">this</span>, <span class="variable">middleware</span> || []);615 616+ <span class="comment">// Default "home" to / </span>617+ <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'home'</span>, <span class="string">'/'</span>);618+619+ <span class="comment">// Set "env" to {EXPRESS,CONNECT}_ENV</span>620+ <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>);621+622 <span class="comment">// Expose objects to each other</span>623 <span class="this">this</span>.<span class="variable">use</span>(<span class="keyword">function</span>(<span class="variable">req</span>, <span class="variable">res</span>, <span class="variable">next</span>){624 <span class="variable">req</span>.<span class="variable">params</span> = <span class="variable">req</span>.<span class="variable">params</span> || {};625 <span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">get</span> = {};11 unmodified lines637 <span class="variable">next</span>();638 });639 640 <span class="comment">// Use router, expose as app.get(), etc</span>635- <span class="this">this</span>.<span class="variable">router</span> = <span class="variable">router</span>(<span class="keyword">function</span>(<span class="variable">app</span>){ <span class="variable">self</span>.<span class="variable">routes</span> = <span class="variable">app</span>; });641+ <span class="keyword">var</span> <span class="variable">fn</span> = <span class="variable">router</span>(<span class="keyword">function</span>(<span class="variable">app</span>){ <span class="variable">self</span>.<span class="variable">routes</span> = <span class="variable">app</span>; });642+ <span class="this">this</span>.<span class="variable">__defineGetter__</span>(<span class="string">'router'</span>, <span class="keyword">function</span>(){643+ <span class="this">this</span>.<span class="variable">__usedRouter</span> = <span class="variable">true</span>;644+ <span class="keyword">return</span> <span class="variable">fn</span>;645+ });646 };</code></pre>647 </td>648 </tr>649 <tr class="code">14 unmodified lines664 <ul><li><p><strong>param</strong>: <em>Number</em> port</p></li><li><p><strong>param</strong>: <em>String</em> host</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>665 </td>666 <td class="code">667 <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>, <span class="variable">host</span>){658- <span class="comment">// Default "home" to the mounted route or '/'</span>659- <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">set</span>(<span class="string">'home'</span>)) {660- <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'home'</span>, <span class="this">this</span>.<span class="variable">route</span> || <span class="string">'/'</span>);661- }662-663- <span class="comment">// Set "env" to {EXPRESS,CONNECT}_ENV</span>664- <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>);665- <span class="this">this</span>.<span class="variable">runConfig</span>(<span class="string">'any'</span>, <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'env'</span>));666-668 <span class="comment">// Setup view reloading</span>669 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">set</span>(<span class="string">'reload views'</span>)) {670 <span class="variable">view</span>.<span class="variable">watcher</span>.<span class="variable">call</span>(<span class="this">this</span>, <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'reload views'</span>));671 }671-672 <span class="variable">connect</span>.<span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">listen</span>.<span class="variable">call</span>(<span class="this">this</span>, <span class="variable">port</span>, <span class="variable">host</span>);673 };</code></pre>674 </td>675 </tr>676 <tr class="code">677 <td class="docs">678+<p>Proxy <code>connect.Server#use()</code> to apply settings to679+mounted applications.</p>680+681+<h2></h2>682+683+<ul><li><p><strong>param</strong>: <em>String | Function | Server</em> route</p></li><li><p><strong>param</strong>: <em>Function | Server</em> middleware</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>684+</td>685+<td class="code">686+<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">use</span> = <span class="keyword">function</span>(<span class="variable">route</span>, <span class="variable">middleware</span>){687+ <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">route</span> !== <span class="string">'string'</span>) {688+ <span class="variable">middleware</span> = <span class="variable">route</span>, <span class="variable">route</span> = <span class="string">'/'</span>;689+ }690+691+ <span class="variable">connect</span>.<span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">use</span>.<span class="variable">call</span>(<span class="this">this</span>, <span class="variable">route</span>, <span class="variable">middleware</span>);692+693+ <span class="comment">// Mounted an app</span>694+ <span class="keyword">if</span> (<span class="variable">middleware</span> <span class="variable">instanceof</span> <span class="class">Server</span>) {695+ <span class="comment">// Home is /:route/:home</span>696+ <span class="keyword">var</span> <span class="variable">app</span> = <span class="variable">middleware</span>,697+ <span class="variable">home</span> = <span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'home'</span>);698+ <span class="keyword">if</span> (<span class="variable">home</span> === <span class="string">'/'</span>) <span class="variable">home</span> = <span class="string">''</span>;699+ <span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'home'</span>, (<span class="variable">app</span>.<span class="variable">route</span> || <span class="string">''</span>) + <span class="variable">home</span>);700+ <span class="comment">// Mounted hook</span>701+ <span class="keyword">if</span> (<span class="variable">app</span>.<span class="variable">__mounted</span>) <span class="variable">app</span>.<span class="variable">__mounted</span>.<span class="variable">call</span>(<span class="variable">app</span>, <span class="this">this</span>);702+ }703+704+ <span class="keyword">return</span> <span class="this">this</span>;705+};</code></pre>706+</td>707+</tr>708+<tr class="code">709+<td class="docs">710+<p>Assign a callback <code>fn</code> which is called711+when this <code>Server</code> is passed to <code>Server#use()</code>.</p>712+713+<h2>Examples</h2>714+715+<p> var app = express.createServer(),716+ blog = express.createServer();</p>717+718+<p> blog.mounted(function(parent){719+ // parent is app720+ // "this" is blog721+ });</p>722+723+<p> app.use(blog);</p>724+725+<h2></h2>726+727+<ul><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>728+</td>729+<td class="code">730+<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">mounted</span> = <span class="keyword">function</span>(<span class="variable">fn</span>){731+ <span class="this">this</span>.<span class="variable">__mounted</span> = <span class="variable">fn</span>;732+ <span class="keyword">return</span> <span class="this">this</span>;733+};</code></pre>734+</td>735+</tr>736+<tr class="code">737+<td class="docs">738 <p>Register the given view helpers <code>obj</code>. This method739 can be called several times to apply additional helpers.</p>740 741 <h2></h2>103 unmodified lines845 </td>846 </tr>847 <tr class="code">848 <td class="docs">789-<p>Disable <code>setting</code>.</p>849+<p>Configure callback for the given <code>env</code>.</p>850 851 <h2></h2>852 793-<ul><li><p><strong>param</strong>: <em>String</em> setting</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>853+<ul><li><p><strong>param</strong>: <em>String</em> env</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>854 </td>855 <td class="code">856 <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>){797- <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>;798- (<span class="this">this</span>.<span class="variable">config</span>[<span class="variable">env</span>] = <span class="this">this</span>.<span class="variable">config</span>[<span class="variable">env</span>] || []).<span class="variable">push</span>(<span class="variable">fn</span>);857+ <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">env</span> === <span class="string">'function'</span>) {858+ <span class="variable">fn</span> = <span class="variable">env</span>, <span class="variable">env</span> = <span class="string">'all'</span>;859+ }860+ <span class="keyword">if</span> (<span class="variable">env</span> === <span class="string">'all'</span> || <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'env'</span>) === <span class="variable">env</span>) {861+ <span class="variable">fn</span>.<span class="variable">call</span>(<span class="this">this</span>);862+ }863 <span class="keyword">return</span> <span class="this">this</span>;864 };865 866 <span class="comment">// Generate routing methods</span>1 unmodified line868 (<span class="keyword">function</span>(<span class="variable">method</span>){869 <span class="class">Server</span>.<span class="variable">prototype</span>[<span class="variable">method</span>] = <span class="keyword">function</span>(<span class="variable">path</span>, <span class="variable">fn</span>){870 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">__usedRouter</span>) {871 <span class="this">this</span>.<span class="variable">use</span>(<span class="this">this</span>.<span class="variable">router</span>);808- <span class="this">this</span>.<span class="variable">__usedRouter</span> = <span class="variable">true</span>;872 }873 <span class="this">this</span>.<span class="variable">routes</span>[<span class="variable">method</span>](<span class="variable">path</span>, <span class="variable">fn</span>);874 <span class="keyword">return</span> <span class="this">this</span>;875 };279 unmodified linesmodified:docs/guide.1+22 added-1 removed
132 unmodified lines133 .IP "\(bu" 4134 \fIenv\fR Application environment set internally, use \fIapp\.set(\'env\')\fR on \fIServer#listen()\fR135 .136 .IP "\(bu" 4137-\fIhome\fR Application base path used with \fIres\.redirect()\fR, when mounted defaults to \fIServer#route\fR, otherwise \"/\"\. Assigned on \fIServer#listen()\fR\.137+\fIhome\fR Application base path used with \fIres\.redirect()\fR, when mounted defaults to \fIServer#route\fR, otherwise \"/\"\.138 .139 .IP "\(bu" 4140 \fIviews\fR Root views directory defaulting to \fBCWD/views\fR141 .916 unmodified lines1058 .fi1059 .1060 .IP "" 01061 .1062+.SS "app\.mounted(fn)"1063+Assign a callback \fIfn\fR which is called when this \fIServer\fR is passed to \fIServer#use()\fR\.1064+.1065+.IP "" 41066+.1067+.nf1068+1069+var app = express\.createServer(),1070+ blog = express\.createServer();1071+1072+blog\.mounted(function(parent){1073+ // parent is app1074+ // \"this\" is blog1075+});1076+1077+app\.use(blog);1078+.1079+.fi1080+.1081+.IP "" 01082+.1083 .SS "app\.listen([port[, host]])"1084 Bind the app server to the given \fIport\fR, which defaults to 3000\. When \fIhost\fR is omitted all connections will be accepted via \fIINADDR_ANY\fR\.1085 .1086 .IP "" 444 unmodified linesmodified:docs/guide.html+17 added-2 removed
210 unmodified lines211 <li><a href="#app-redirect-name-val-">app.redirect()</a></li>212 <li><a href="#app-error-function-">app.error()</a></li>213 <li><a href="#app-helpers-obj-">app.helpers()</a></li>214 <li><a href="#app-dynamicHelpers-obj-">app.dynamicHelpers()</a></li>215+<li><a href="#app-mounted-fn-">app.mounted()</a></li>216 <li><a href="#app-listen-port-host-">app.listen()</a></li>217 </ul>218 <a href='http://github.com/visionmedia/express' id='logo'>Express</a> 219 <p id="tagline">92 unmodified lines312 <p>Express supports the following settings out of the box:</p>313 314 <ul>315 <li><em>env</em> Application environment set internally, use <em>app.set('env')</em> on <em>Server#listen()</em></li>315-<li><em>home</em> Application base path used with <em>res.redirect()</em>, when mounted defaults316-to <em>Server#route</em>, otherwise "/". Assigned on <em>Server#listen()</em>.</li>316+<li><em>home</em> Application base path used with <em>res.redirect()</em>, when mounted defaults to <em>Server#route</em>, otherwise "/".</li>317 <li><em>views</em> Root views directory defaulting to <strong>CWD/views</strong></li>318 <li><em>view engine</em> Default view engine name for views rendered without extensions</li>319 <li><em>reload views</em> Reloads altered views, by default watches for <em>mtime</em> changes with320 with a 5 minute interval. Example: <em>app.set('reload views', 60000);</em></li>599 unmodified lines920 921 <pre><code><%= session.name %>922 </code></pre>923 924+<h3 id="app-mounted-fn-">app.mounted(fn)</h3>925+926+<p>Assign a callback <em>fn</em> which is called when this <em>Server</em> is passed to <em>Server#use()</em>.</p>927+928+<pre><code>var app = express.createServer(),929+ blog = express.createServer();930+931+blog.mounted(function(parent){932+ // parent is app933+ // "this" is blog934+});935+936+app.use(blog);937+</code></pre>938+939 <h3 id="app-listen-port-host-">app.listen([port[, host]])</h3>940 941 <p>Bind the app server to the given <em>port</em>, which defaults to 3000. When <em>host</em> is omitted all942 connections will be accepted via <em>INADDR_ANY</em>.</p>28 unmodified linesmodified:docs/guide.md+15 added-2 removed
75 unmodified lines76 77 Express supports the following settings out of the box:78 79 * _env_ Application environment set internally, use _app.set('env')_ on _Server#listen()_80- * _home_ Application base path used with _res.redirect()_, when mounted defaults81- to _Server#route_, otherwise "/". Assigned on _Server#listen()_.80+ * _home_ Application base path used with _res.redirect()_, when mounted defaults to _Server#route_, otherwise "/".81 * _views_ Root views directory defaulting to **CWD/views**82 * _view engine_ Default view engine name for views rendered without extensions83 * _reload views_ Reloads altered views, by default watches for _mtime_ changes with84 with a 5 minute interval. Example: _app.set('reload views', 60000);_530 unmodified lines615 All views would now have _session_ available so that session data can be accessed via _session.name_ etc:616 617 <%= session.name %>618 619+### app.mounted(fn)620+621+Assign a callback _fn_ which is called when this _Server_ is passed to _Server#use()_.622+623+ var app = express.createServer(),624+ blog = express.createServer();625+ 626+ blog.mounted(function(parent){627+ // parent is app628+ // "this" is blog629+ });630+ 631+ app.use(blog);632+633 ### app.listen([port[, host]])634 635 Bind the app server to the given _port_, which defaults to 3000. When _host_ is omitted all636 connections will be accepted via _INADDR_ANY_.19 unmodified lines