migrate.1
This file
Path
docs/migrate.1
347 lines · 6.0 KiB
Last changed by
Updated docsTj Holowaychukbefore adoptioncacada8
History of this fileTake it
The walk stopped after 200 commits: lines older than 9750817 point at it.
Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 1–5why, one step back1.\" generated with Ronn/v0.6.62.\" http://github.com/rtomayko/ronn/3.4.TH "MIGRATE" "" "July 2010" "" ""5.Started guideTj Holowaychukbefore adoption9e3a0c6
lines 6–7why, one step back6.SS "Built On Connect"7Express 1\.x is written to run on\-top of the Connect \fIhttp://extjs\.github\.com/Connect\fR middlware framework, thus the \fIPlugin\fR has been replaced by Connect\'s middleware\. By abstracting our middleware to Connect we allow additional community frameworks to develop robust, high\-level frameworks using the same technologies as Express\.Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 8–30why, one step back8.9.SS "Creating Applications"10Previously due to legacy code implemented in the early days of node, Express unfortunately had some globals\. The DSL would previously be accessed as shown below:11.12.IP "" 413.14.nf1516require(\'express\');1718configure(function(){19 // app configuration20});2122get(\'/\', function(){23 return \'hello world\';24});25.26.fi27.28.IP "" 029.30.PRemoved backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 31why, one step back31Now we utilize the CommonJS module system appropriately, and introduce \fIexpress\.createServer()\fR which accepts the same arguments as \fIhttp\.createServer()\fR:Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 32–51why, one step back32.33.IP "" 434.35.nf3637var express = require(\'express\'),38 app = express\.createServer();3940app\.configure(function(){41 // app configuration42});4344app\.get(\'/\', function(req, res){45 res\.send(\'hello world\');46});47.48.fi49.50.IP "" 051.Added view rendering migration sectionTj Holowaychukbefore adoption0b86ce2
line 52why, one step back52.PDocs for plugins vs middlewareTj Holowaychukbefore adoption927aae7
lines 53–70why, one step back53Express 1\.x does \fInot\fR currently allow returning of a string\.54.55.SS "Plugins vs Middleware"56Previously Express was bundled with plugins, which were essentially what are now Connect middleware\. Previously plugins would be utilized in a manor similar to below:57.58.IP "" 459.60.nf6162use(Logger);63use(MethodOverride);64use(Cookie);65.66.fi67.68.IP "" 069.70.PRemoved backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 71why, one step back71Which we can now \fIuse()\fR within our app, or pass to the \fIexpress\.createServer()\fR method:Docs for plugins vs middlewareTj Holowaychukbefore adoption927aae7
lines 72–98why, one step back72.73.IP "" 474.75.nf7677var connect = require(\'connect\');7879var app = express\.createServer(80 connect\.logger(),81 connect\.methodOverride(),82 connect\.cookie()83);84.85.fi86.87.IP "" 088.89.P90or:91.92.IP "" 493.94.nf9596var connect = require(\'connect\');97var app = express\.createServer();98Updated docsTj Holowaychukbefore adoptioncacada8
lines 99–101why, one step back99app\.use(connect\.logger());100app\.use(connect\.methodOverride());101app\.use(connect\.cookieDecoder());Docs for plugins vs middlewareTj Holowaychukbefore adoption927aae7
lines 102–108why, one step back102.103.fi104.105.IP "" 0106.107.P108For documentation on creating Connect middleware visit Middleware Authoring \fIhttp://extjs\.github\.com/Connect/#Middleware\-Authoring\fR\.Added view rendering migration sectionTj Holowaychukbefore adoption0b86ce2
line 109why, one step back109.Started migration docsTj Holowaychukbefore adoption9e68a5b
line 110why, one step back110.SS "Running Applications"Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 111why, one step back111Previously a global function \fIrun()\fR, was available:Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 112–123why, one step back112.113.IP "" 4114.115.nf116117run();118.119.fi120.121.IP "" 0122.123.PRemoved backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 124why, one step back124The new \fIexpress\.Server\fR has the same API as \fIhttp\.Server\fR, so we can do things like:Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 125–135why, one step back125.126.IP "" 4127.128.nf129130app\.listen();131app\.listen(3000);132.133.fi134.135.IP "" 0Migration docs for paramsTj Holowaychukbefore adoptionda84c0b
lines 136–137why, one step back136.137.SS "Route Parameters"Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 138why, one step back138Previously we could use \fIthis\.param()\fR to attempt fetching a route, query string, or request body parameter:Migration docs for paramsTj Holowaychukbefore adoptionda84c0b
lines 139–152why, one step back139.140.IP "" 4141.142.nf143144get(\'/user/:id\', function(){145 this\.param(\'id\');146});147.148.fi149.150.IP "" 0151.152.PMigration docs for req.param()Tj Holowaychukbefore adoptiondc77894
lines 153–158why, one step back153Polymorphic parameter access can be done using \fBreq\.param()\fR:154.155.IP "" 4156.157.nf158Fixed migration typoTj Holowaychukbefore adoptiona9c3f56
line 159why, one step back159app\.get(\'/user/:id\', function(req, res){Migration docs for req.param()Tj Holowaychukbefore adoptiondc77894
lines 160–168why, one step back160 req\.param(\'id\');161});162.163.fi164.165.IP "" 0166.167.P168Route parameters are also passed as the third argument:Migration docs for paramsTj Holowaychukbefore adoptionda84c0b
lines 169–180why, one step back169.170.IP "" 4171.172.nf173174app\.get(\'/user/:id\', function(req, res, params){175 params\.id;176});177.178.fi179.180.IP "" 0Control passing docsTj Holowaychukbefore adoption548a070
lines 181–197why, one step back181.182.SS "Passing Route Control"183Old express had a weak notion of route passing, which did not support async, and was never properly implemented for practical use:184.185.IP "" 4186.187.nf188189get(\'/\', function(){190 this\.pass(\'/foobar\');191});192.193.fi194.195.IP "" 0196.197.PRemoved backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 198why, one step back198Now Express has access to Connect\'s \fInext()\fR function, which is passed as the fourth and final argument\. Calling \fInext()\fR will pass control to the next \fImatching route\fR, or continue down the stack of Connect middleware\.Control passing docsTj Holowaychukbefore adoption548a070
lines 199–209why, one step back199.200.IP "" 4201.202.nf203204app\.get(\'/user/:id?\', function(req, res, params, next){205 next();206});207208app\.get(\'/user\', function(){209 // \.\.\. respondAdded view rendering migration sectionTj Holowaychukbefore adoption0b86ce2
lines 210–216why, one step back210});211.212.fi213.214.IP "" 0215.216.SS "View Rendering"Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 217why, one step back217View filenames no longer take the form \fINAME\fR\.\fITYPE\fR\.\fIENGINE\fR, the \fIContent\-Type\fR can be set via \fIres\.contentType()\fR or \fIres\.header()\fR\. For example what was previously \fIlayout\.html\.haml\fR, should now be \fIlayout\.haml\fR\.Added view rendering migration sectionTj Holowaychukbefore adoption0b86ce2
lines 218–236why, one step back218.219.P220Previously a view render looked something like this:221.222.IP "" 4223.224.nf225226get(\'/\', function(){227 this\.render(\'index\.html\.haml\', {228 locals: { title: \'My Site\' }229 });230});231.232.fi233.234.IP "" 0235.236.PRemoved backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 237why, one step back237We now have \fIres\.render()\fR, however the options passed to haml \fIhttp://github\.com/visionmedia/haml\.js\fR, jade \fIhttp://github\.com/visionmedia/jade\fR, and others remain the same\.Added view rendering migration sectionTj Holowaychukbefore adoption0b86ce2
lines 238–246why, one step back238.239.IP "" 4240.241.nf242243app\.get(\'/\', function(req, res){244 res\.render(\'index\.haml\', {245 locals: { title: \'My Site\' }246 });Control passing docsTj Holowaychukbefore adoption548a070
lines 247–251why, one step back247});248.249.fi250.251.IP "" 0Added partial migration docsTj Holowaychukbefore adoption2a674f4
lines 252–253why, one step back252.253.PRemoved backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 254why, one step back254Previously rendering of a collection via \fIpartial()\fR would look something like this:Added partial migration docsTj Holowaychukbefore adoption2a674f4
lines 255–266why, one step back255.256.IP "" 4257.258.nf259260this\.partial(\'comment\.html\.haml\', { collection: comments });261.262.fi263.264.IP "" 0265.266.PRemoved backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 267why, one step back267Although this worked just fine, it was generally to verbose, the similar but new API looks like this, as \fIpartial()\fR is \fIalways\fR passed as a local variable:Added partial migration docsTj Holowaychukbefore adoption2a674f4
lines 268–279why, one step back268.269.IP "" 4270.271.nf272273partial(\'comment\.haml\', { collection: comments });274.275.fi276.277.IP "" 0278.279.PAdded more view docsTj Holowaychukbefore adoption2f96506
line 280why, one step back280To make things even less verbose we can assume the extension when omitted:Added partial migration docsTj Holowaychukbefore adoption2a674f4
lines 281–303why, one step back281.282.IP "" 4283.284.nf285286partial(\'comment\', { collection: comments });287.288.fi289.290.IP "" 0291.292.P293And once again even further, when rendering a collection we can simply pass an array, if no other options are desired:294.295.IP "" 4296.297.nf298299partial(\'comments\', comments);300.301.fi302.303.IP "" 0Added redirect migration docsTj Holowaychukbefore adoption74432a6
line 304why, one step back304.Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7
line 305why, one step back305.SS "Redirecting"Added redirect migration docsTj Holowaychukbefore adoption74432a6
lines 306–318why, one step back306Previously you would307.308.IP "" 4309.310.nf311312this\.redirect(\'/somewhere\');313.314.fi315.316.IP "" 0317.318.PMerge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7
line 319why, one step back319However you would now:Added redirect migration docsTj Holowaychukbefore adoption74432a6
lines 320–325why, one step back320.321.IP "" 4322.323.nf324325res\.redirect(\'/somewhere\');Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7
line 326why, one step back326res\.redirect(\'/somewhere\', 301);Added redirect migration docsTj Holowaychukbefore adoption74432a6
lines 327–330why, one step back327.328.fi329.330.IP "" 0Added contrib docsTj Holowaychukbefore adoptionf0ba57b
lines 331–346why, one step back331.332.SS "HTTP Client"333Previously Express provided a high level http client, this library is no more as it does not belong in Express, however it may be resurrected as a separate module\.334.335.SS "Core Extensions"336Express is no longer dependent on the JavaScript Extensions \fIhttp://github\.com/visionmedia/ext\.js\fR library, so those of you using the methods provided by it such as \fBObject\.merge(a, b)\fR will need to roll your own, or install the module via:337.338.IP "" 4339.340.nf341342$ npm install ext343.344.fi345.346.IP "" 0Started migration docsTj Holowaychukbefore adoption9e68a5b
line 347why, one step back347