migrate.html
This file
Path
docs/migrate.html
408 lines · 10.9 KiB · HTML
Last changed by
Rebuilt docsTj Holowaychukbefore adoption2724ce3
History of this fileTake it
The walk stopped after 200 commits: lines older than 75661a2 point at it.
Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 1–3why, one step back1<html>2 <head>3 <title>Express - node web framework</title>Merge branch 'guide'Tj Holowaychukbefore adoptionf4a0809
line 4why, one step back4 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 5–18why, one step back5 <style>6 #tagline {7 margin-left: 75px;8 margin-bottom: 30px;9 color: rgba(255,255,255,0.7); }10 html {11 background: #1c1c1c url(images/bg.tile.jpg); }1213 body {14 margin: 0;15 padding-bottom: 30px;16 font: 14px/1.4 "Helvetica Neue", "Lucida Grande", "Arial";17 font-size: 14px;18 line-height: 1.5;antialiased textTj Holowaychukbefore adoption8d80f23
line 19why, one step back19 -webkit-font-smoothing: antialiased;Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 20–41why, one step back20 background: url(images/bg.jpg) 50% 0 no-repeat;21 color: #8b8b8b; }2223 * {24 outline: none; }2526 em {27 color: white; }2829 a img {30 border: none !important; }3132 a {33 font-weight: bold;34 text-decoration: none;35 color: white;36 -webkit-transition-property: opacity, -webkit-transform, color, background-color, padding, -webkit-box-shadow;37 -webkit-transition-duration: 0.15s;38 -webkit-transition-timing-function: ease-out; }39 a:hover {40 opacity: 0.8; }41HTTP verb docs. Closes #415Tj Holowaychukbefore adoptiond89b951
line 42why, one step back42 h1, h2, h3, h4 {Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 43–48why, one step back43 margin: 45px 0 0 0;44 color: white;45 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }4647 h3 {48 font-size: 18px; }HTTP verb docs. Closes #415Tj Holowaychukbefore adoptiond89b951
lines 49–52why, one step back49 h4 {50 margin-left: 10px;51 font-size: 14px;52 }Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 53–73why, one step back5354 pre {55 margin: 20px 10px;56 padding: 25px 20px;57 background: rgba(0,0,0,0.5);58 border: 1px solid #323232;59 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);60 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);61 -webkit-border-radius: 5px;62 -moz-border-radius: 5px; }6364 code {65 font-family: "Helvetica Neue", "Lucida Grande", "Arial"; }6667 ul {68 margin: 15px 0;69 padding: 0 0 0 35px; }70 ul li {71 margin: 0;72 padding: 2px 0;73 list-style: square; }Merge branch 'guide'Tj Holowaychukbefore adoptionf4a0809
lines 74–77why, one step back74 ul li ul {75 margin: 0;76 padding-left: 12px;77 }Route callback signature changedTj Holowaychukbefore adoption75661a2
line 78why, one step back78Merge branch 'guide'Tj Holowaychukbefore adoptionf4a0809
lines 79–80why, one step back79 .man-name, #Express { display:none; }80Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 81–109why, one step back81 .sect {82 margin-left: 40px; }8384 #logo {85 display: block;86 margin-left: 30%;87 margin-bottom: 30px;88 width: 194px;89 height: 51px;90 background: url(images/logo.png) 0 0 no-repeat;91 text-indent: -99999px; }92 #logo:hover {93 opacity: 0.7; }94 #logo:active {95 opacity: 0.3; }9697 #ribbon {98 position: fixed;99 top: 0;100 right: 0;101 z-index: 2; }102103 #wrapper {104 width: 100%;105 min-height: 800px;106 background: url(images/top.png) 0 0 repeat-x; }107108 #container {109 margin: 0 auto;Regenerated docs againTj Holowaychukbefore adoption8ead901
line 110why, one step back110 padding-top: 80px;Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 111–114why, one step back111 width: 550px; }112113 #toc {114 position: fixed;Regenerated docs againTj Holowaychukbefore adoption8ead901
line 115why, one step back115 top: 0;Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 116–120why, one step back116 left: 0;117 margin: 0 0 0 15px;118 padding: 15px;119 height: 100%;120 background: rgba(0,0,0,0.2);Merge branch 'fix-toc'Tj Holowaychukbefore adoptionbb18f87
line 121why, one step back121 overflow: auto;Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 122–158why, one step back122 border-right: 1px solid rgba(255,255,255,0.05);123 }124 #toc li {125 padding: 0;126 list-style: none;127 }128 #toc li a {129 font-size: 11px;130 }131 #menu {132 margin-left: 65px;133 padding: 0;134 padding-bottom: 30px; }135 #menu li {136 display: inline;137 list-style: none; }138 #menu li a {139 display: block;140 float: left;141 margin: 0 2px;142 padding: 3px 15px;143 background: rgba(0,0,0,0.2);144 -webkit-border-radius: 8px;145 -moz-border-radius: 8px;146 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);147 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);148 -webkit-transition-property: opacity, -webkit-transform, color, background-color, -webkit-box-shadow;149 -webkit-transition-duration: 0.15s;150 -webkit-transition-timing-function: ease-out; }151 #menu li a:hover,152 #menu li a.active {153 background: rgba(0,0,0,0.5); }154 #menu li a:active {155 background: rgba(0,0,0,0.1);156 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.4);157 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.4); }158 </style>Merge branch 'guide'Tj Holowaychukbefore adoptionf4a0809
lines 159–170why, one step back159 <script>160 $(function(){161 $('.section').hide();162 $('.toggle, a.section-title').toggle(function(){163 $(this).siblings('ul').fadeIn(300);164 return false;165 }, function(){166 $(this).siblings('ul').fadeOut(300);167 return false;168 });169 });170 </script>Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 171–189why, one step back171 </head>172 <body>173 <a href='http://github.com/visionmedia/express'> 174 <img alt='Fork me on GitHub' id='ribbon' src='http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png' /> 175 </a>176 <div id="wrapper">177 <div id="container">178 <a href='http://github.com/visionmedia/express' id='logo'>Express</a> 179 <p id="tagline">180 High performance, high class web development for181 <a href="http://nodejs.org">Node.js</a>182 </p>183 <ul id="menu">184 <li><a href="index.html">Home</a></li>185 <li><a href="guide.html">Guide</a></li>186 <li><a href="contrib.html">Contributing</a></li>187 <li><a href="migrate.html">1.x Migration</a></li>188 </ul>189<div class='mp'>Merge branch 'guide'Tj Holowaychukbefore adoptionf4a0809
lines 190–193why, one step back190<h2 id="Express">Express</h2>191<p class="man-name">192 <code>migrate</code>193</p>Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 194–248why, one step back194<h3 id="Built-On-Connect">Built On Connect</h3>195196<p>Express 1.x is written to run on-top of the <a href="http://extjs.github.com/Connect">Connect</a> middlware197framework, thus the <em>Plugin</em> has been replaced by Connect's middleware. By abstracting our middleware198to Connect we allow additional community frameworks to develop robust, high-level frameworks using199the same technologies as Express.</p>200201<h3 id="Creating-Applications">Creating Applications</h3>202203<p>Previously due to legacy code implemented in the early days of node,204Express unfortunately had some globals. The DSL would previously be205accessed as shown below:</p>206207<pre><code>require('express');208209configure(function(){210 // app configuration211});212213get('/', function(){214 return 'hello world';215});216</code></pre>217218<p>Now we utilize the CommonJS module system appropriately, and219introduce <em>express.createServer()</em> which accepts the same arguments220as <em>http.createServer()</em>:</p>221222<pre><code>var express = require('express'),223 app = express.createServer();224225app.configure(function(){226 // app configuration227});228229app.get('/', function(req, res){230 res.send('hello world');231});232</code></pre>233234<p>Express 1.x does <em>not</em> currently allow returning of a string.</p>235236<h3 id="Plugins-vs-Middleware">Plugins vs Middleware</h3>237238<p>Previously Express was bundled with plugins, which were essentially what239are now Connect middleware. Previously plugins would be utilized in a manor240similar to below:</p>241242<pre><code>use(Logger);243use(MethodOverride);244use(Cookie);245</code></pre>246247<p>Which we can now <em>use()</em> within our app, or pass to the <em>express.createServer()</em> method:</p>248Added app.register() docsTj Holowaychukbefore adoption77e5d8e
lines 249–252why, one step back249<pre><code>var app = express.createServer(250 express.logger(),251 express.methodOverride(),252 express.cookieDecoder()Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 253–257why, one step back253);254</code></pre>255256<p>or:</p>257Added app.register() docsTj Holowaychukbefore adoption77e5d8e
line 258why, one step back258<pre><code>var app = express.createServer();Route callback signature changedTj Holowaychukbefore adoption75661a2
line 259why, one step back259Added app.register() docsTj Holowaychukbefore adoption77e5d8e
lines 260–262why, one step back260app.use(express.logger());261app.use(express.methodOverride());262app.use(express.cookieDecoder());Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 263–297why, one step back263</code></pre>264265<p>For documentation on creating Connect middleware visit <a href="http://extjs.github.com/Connect/#Middleware-Authoring">Middleware Authoring</a>.</p>266267<h3 id="Running-Applications">Running Applications</h3>268269<p>Previously a global function <em>run()</em>, was available:</p>270271<pre><code>run();272</code></pre>273274<p>The new <em>express.Server</em> has the same API as <em>http.Server</em>,275so we can do things like:</p>276277<pre><code>app.listen();278app.listen(3000);279</code></pre>280281<h3 id="Route-Parameters">Route Parameters</h3>282283<p>Previously we could use <em>this.param()</em> to attempt284fetching a route, query string, or request body parameter:</p>285286<pre><code>get('/user/:id', function(){287 this.param('id');288});289</code></pre>290291<p>Polymorphic parameter access can be done using <code>req.param()</code>:</p>292293<pre><code>app.get('/user/:id', function(req, res){294 req.param('id');295});296</code></pre>297Updated docsTj Holowaychukbefore adoptiond691ecb
line 298why, one step back298<p>Route parameters are available via <code>req.params</code>:</p>Route callback signature changedTj Holowaychukbefore adoption75661a2
line 299why, one step back299Updated docsTj Holowaychukbefore adoptiond691ecb
lines 300–301why, one step back300<pre><code>app.get('/user/:id', function(req, res){301 req.params.id;Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 302–316why, one step back302});303</code></pre>304305<h3 id="Passing-Route-Control">Passing Route Control</h3>306307<p>Old express had a weak notion of route passing,308which did not support async, and was never properly309implemented for practical use:</p>310311<pre><code>get('/', function(){312 this.pass('/foobar');313});314</code></pre>315316<p>Now Express has access to Connect's <em>next()</em> function,Updated docsTj Holowaychukbefore adoptiond691ecb
line 317why, one step back317which is passed as the third and final argument. Calling <em>next()</em> willRoute callback signature changedTj Holowaychukbefore adoption75661a2
lines 318–320why, one step back318pass control to the next <em>matching route</em>, or continue down the stack319of Connect middleware.</p>320Updated docsTj Holowaychukbefore adoptiond691ecb
line 321why, one step back321<pre><code>app.get('/user/:id?', function(req, res, next){Route callback signature changedTj Holowaychukbefore adoption75661a2
lines 322–408why, one step back322 next();323});324325app.get('/user', function(){326 // ... respond327});328</code></pre>329330<h3 id="View-Rendering">View Rendering</h3>331332<p>View filenames no longer take the form <em>Express</em>.<em>TYPE</em>.<em>ENGINE</em>,333the <em>Content-Type</em> can be set via <em>res.contentType()</em> or334<em>res.header()</em>. For example what was previously <em>layout.html.haml</em>,335should now be <em>layout.haml</em>.</p>336337<p>Previously a view render looked something like this:</p>338339<pre><code>get('/', function(){340 this.render('index.html.haml', {341 locals: { title: 'My Site' }342 });343});344</code></pre>345346<p>We now have <em>res.render()</em>, however the options passed to <a href="http://github.com/visionmedia/haml.js">haml</a>, <a href="http://github.com/visionmedia/jade">jade</a>, and others347remain the same.</p>348349<pre><code>app.get('/', function(req, res){350 res.render('index.haml', {351 locals: { title: 'My Site' }352 });353});354</code></pre>355356<p>Previously rendering of a collection via <em>partial()</em> would look something like this:</p>357358<pre><code>this.partial('comment.html.haml', { collection: comments });359</code></pre>360361<p>Although this worked just fine, it was generally to verbose, the similar but new API362looks like this, as <em>partial()</em> is <em>always</em> passed as a local variable:</p>363364<pre><code>partial('comment.haml', { collection: comments });365</code></pre>366367<p>To make things even less verbose we can assume the extension when omitted:</p>368369<pre><code>partial('comment', { collection: comments });370</code></pre>371372<p>And once again even further, when rendering a collection we can simply pass373an array, if no other options are desired:</p>374375<pre><code>partial('comments', comments);376</code></pre>377378<h3 id="Redirecting">Redirecting</h3>379380<p>Previously you would</p>381382<pre><code>this.redirect('/somewhere');383</code></pre>384385<p>However you would now:</p>386387<pre><code>res.redirect('/somewhere');388res.redirect('/somewhere', 301);389</code></pre>390391<h3 id="HTTP-Client">HTTP Client</h3>392393<p>Previously Express provided a high level http client, this library is no more394as it does not belong in Express, however it may be resurrected as a separate module.</p>395396<h3 id="Core-Extensions">Core Extensions</h3>397398<p>Express is no longer dependent on the <a href="http://github.com/visionmedia/ext.js">JavaScript Extensions</a> library, so those of you using the methods provided by it such as <code>Object.merge(a, b)</code> will need to399roll your own, or install the module via:</p>400401<pre><code>$ npm install ext402</code></pre>403404</div>405 </div>406 </div>407 </body>408</html>