Skip to content
Myr

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 c1a82bf · Browse files · 3 files+274 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+274 added−1 removed

  • other:+274 added−1 removed

3 files+274 added−1 removed

modified:docs/migrate.1+123 added
75 unmodified lines
76.77.fi78.79.IP "" 080.81.SS "req\.param(name[, defaultValue])"82Previously only \fIname\fR was accepted, so some of you may have been doing the following:83.84.IP "" 485.86.nf8788 var id = req\.param(\'id\') || req\.user\.id;89.90.fi91.92.IP "" 093.94.P95The new \fIdefaultValue\fR argument can handle this nicely:96.97.IP "" 498.99.nf100101 var id = req\.param(\'id\', req\.user\.id);102.103.fi104.105.IP "" 0106.107.SS "app\.helpers() / app\.locals()"108\fIapp\.locals()\fR is now an alias of \fIapp\.helpers()\fR, as helpers makes more sense for functions\.109.110.SS "req\.accepts(type)"111\fIreq\.accepts()\fR now accepts extensions:112.113.IP "" 4114.115.nf116117 // Accept: text/html118 req\.accepts(\'html\');119 req\.accepts(\'\.html\');120 // => true121122 // Accept: text/*; application/json123 req\.accepts(\'html\');124 req\.accepts(\'text/*\');125 req\.accepts(\'text/plain\');126 req\.accepts(\'application/json\');127 // => true128129 req\.accepts(\'image/png\');130 req\.accepts(\'png\');131 // => false132.133.fi134.135.IP "" 0136.137.SS "res\.download() / res\.sendfile()"138Both of these methods now utilize Connect\'s static file server behind the scenes (actually the previous Express code was ported to Connect 1\.0)\. With this change comes a change to the callback as well\. Previously the \fIpath\fR and \fIstream\fR were passed, however now only an \fIerror\fR is passed, when no error has occurred the callback will be invoked indicating that the file transfer is complete\. The callback remains optional:139.140.IP "" 4141.142.nf143144 res\.download(\'/path/to/file\');145146 res\.download(\'/path/to/file\', function(err){147 if (err) {148 console\.error(err);149 } else {150 console\.log(\'transferred\');151 }152 });153.154.fi155.156.IP "" 0157.158.P159The \fIstream threshold\fR setting was removed\.160.161.SS "View Engine Compliance"162To comply with Express previously engines needed the following signature:163.164.IP "" 4165.166.nf167168 engine\.render(str, options, function(err){});169.170.fi171.172.IP "" 0173.174.P175Now they must export a \fIcompile()\fR function, returning a function which when called with local variables will render the template\. This allows Express to cache the compiled function in memory during production\.176.177.IP "" 4178.179.nf180181 var fn = engine\.compile(str, options);182 fn(locals);183.184.fi185.186.IP "" 0187.188.SS "View Partial Lookup"189Previously partials were loaded relative to the now removed \fIview partials\fR directory setting, or by default \fIviews/partials\fR, now they are relative to the view calling them, read more on view lookup \fIguide\.html#View\-lookup\fR\.190.191.SS "Mime Types"192Express and Connect now utilize the \fImime\fR module in npm, so to add more use:193.194.IP "" 4195.196.nf197198 require(\'mime\')\.define({ \'foo/bar\': [\'foo\', \'bar\'] });199.200.fi201.202.IP "" 0203
modified:docs/migrate.html+78 added
238 unmodified lines
239 res.render('user');240 });241</code></pre>242243<h3 id="req-param-name-defaultValue-">req.param(name[, defaultValue])</h3>244245<p> Previously only <em>name</em> was accepted, so some of you may have been doing the following:</p>246247<pre><code> var id = req.param('id') || req.user.id;248</code></pre>249250<p> The new <em>defaultValue</em> argument can handle this nicely:</p>251252<pre><code> var id = req.param('id', req.user.id);253</code></pre>254255<h3 id="app-helpers-app-locals-">app.helpers() / app.locals()</h3>256257<p> <em>app.locals()</em> is now an alias of <em>app.helpers()</em>, as helpers makes more sense for functions.</p>258259<h3 id="req-accepts-type-">req.accepts(type)</h3>260261<p> <em>req.accepts()</em> now accepts extensions:</p>262263<pre><code> // Accept: text/html264 req.accepts('html');265 req.accepts('.html');266 // =&gt; true267268 // Accept: text/*; application/json269 req.accepts('html');270 req.accepts('text/*');271 req.accepts('text/plain');272 req.accepts('application/json');273 // =&gt; true274275 req.accepts('image/png');276 req.accepts('png');277 // =&gt; false278</code></pre>279280<h3 id="res-download-res-sendfile-">res.download() / res.sendfile()</h3>281282<p> Both of these methods now utilize Connect's static file server behind the scenes (actually the previous Express code was ported to Connect 1.0). With this change comes a change to the callback as well. Previously the <em>path</em> and <em>stream</em> were passed, however now only an <em>error</em> is passed, when no error has occurred the callback will be invoked indicating that the file transfer is complete. The callback remains optional:</p>283284<pre><code> res.download('/path/to/file');285286 res.download('/path/to/file', function(err){287 if (err) {288 console.error(err);289 } else {290 console.log('transferred');291 }292 });293</code></pre>294295<p> The <em>stream threshold</em> setting was removed.</p>296297<h3 id="View-Engine-Compliance">View Engine Compliance</h3>298299<p> To comply with Express previously engines needed the following signature:</p>300301<pre><code> engine.render(str, options, function(err){});302</code></pre>303304<p> Now they must export a <em>compile()</em> function, returning a function which when called with local variables will render the template. This allows Express to cache the compiled function in memory during production.</p>305306<pre><code> var fn = engine.compile(str, options);307 fn(locals);308</code></pre>309310<h3 id="View-Partial-Lookup">View Partial Lookup</h3>311312<p> Previously partials were loaded relative to the now removed <em>view partials</em> directory setting, or by default <em>views/partials</em>, now they are relative to the view calling them, read more on <a href="guide.html#View-lookup">view lookup</a>.</p>313314<h3 id="Mime-Types">Mime Types</h3>315316<p> Express and Connect now utilize the <em>mime</em> module in npm, so to add more use:</p>317318<pre><code> require('mime').define({ 'foo/bar': ['foo', 'bar'] });319</code></pre>320321</div>322 </div>323 </div>324 </body>
1 unmodified line
modified:docs/migrate.md+73 added-1 removed