Updated 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 90a1a2f · Browse files · 2 files·+27 added−22 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+27 added−22 removed
- other:+27 added−22 removed
Provenance
- Commit
344218f- Tree
d72bc21- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
90a1a2f
2 files changed+27 added−22 removed
modified:docs/guide.md+21 added-13 removed
40 unmodified lines41 Note the use of _app.router_, which can (optionally) be used to mount the application routes,42 otherwise the first call to _app.{get,put,del,post}()_ will mount the routes.43 44 app.configure(function(){45- app.use(connect.methodOverride());46- app.use(connect.bodyDecoder());45+ app.use(express.methodOverride());46+ app.use(express.bodyDecoder());47 app.use(app.router);48- app.use(connect.staticProvider(__dirname + '/public'));48+ app.use(express.staticProvider(__dirname + '/public'));49 });50 51 app.configure('development', function(){52- app.use(connect.errorHandler({ dumpExceptions: true, showStack: true }));52+ app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));53 });54 55 app.configure('production', function(){56- app.use(connect.errorHandler());56+ app.use(express.errorHandler());57 });58 59 For internal and arbitrary settings Express provides the _set(key[, val])_, _enable(key)_, _disable(key)_ methods:60 113 unmodified lines174 175 The Express _Plugin_ is no more! middleware via [Connect](http://github.com/extjs/Connect) can be176 passed to _express.createServer()_ as you would with a regular Connect server. For example:177 178- var connect = require('connect'),179- express = require('express');178+ var express = require('express');179 180 var app = express.createServer(182- connect.logger(),183- connect.bodyDecoder()181+ express.logger(),182+ express.bodyDecoder()183 );184 185 Alternatively we can _use()_ them which is useful when adding middleware within _configure()_ blocks:186 188- app.use(connect.logger({ format: ':method :uri' }));187+ app.use(express.logger({ format: ':method :uri' }));188 189+Typically with connect middleware you would _require('connect')_ like so:190+191+ var connect = require('connect');192+ app.use(connect.logger());193+194+This is somewhat annoying, so express re-exports these middleware properties, however they are _identical_:195+196+ app.use(express.logger());197+198 ### Error Handling199 200 Express provides the _app.error()_ method which receives exceptions thrown within a route,201 or passed to _next(err)_. Below is an example which serves different pages based on our41 unmodified lines243 Our apps could also utilize the Connect _errorHandler_ middleware244 to report on exceptions. For example if we wish to output exceptions 245 in "development" mode to _stderr_ we can use:246 239- app.use(connect.errorHandler({ dumpExceptions: true }));247+ app.use(express.errorHandler({ dumpExceptions: true }));248 249 Also during development we may want fancy html pages to show exceptions250 that are passed or thrown, so we can set _showStack_ to true:251 244- app.use(connect.errorHandler({ showStack: true, dumpExceptions: true }));252+ app.use(express.errorHandler({ showStack: true, dumpExceptions: true }));253 254 The _errorHandler_ middleware also responds with _json_ if _Accept: application/json_255 is present, which is useful for developing apps that rely heavily on client-side JavaScript.256 124 unmodified lines381 - Checks urlencoded body params (_req.body_), ex: id=12382 383 To utilize urlencoded request bodies, _req.body_384 should be an object. This can be done by using377-the _connect.bodyDecoder_ middleware.385+the _express.bodyDecoder_ middleware.386 387 ### req.flash(type[, msg])388 389 Queue flash _msg_ of the given _type_.295 unmodified linesmodified:docs/migrate.md+6 added-9 removed
49 unmodified lines505152535455545758595556575859606164626367686964656667686970119 unmodified linesExpand all49 unmodified lines use(Cookie);
Which we can now _use()_ within our app, or pass to the _express.createServer()_ method:
var connect = require('connect');
var app = express.createServer( connect.logger(), connect.methodOverride(), connect.cookieDecoder() express.logger(), express.methodOverride(), express.cookieDecoder() );
or:
var connect = require('connect'); var app = express.createServer();
app.use(connect.logger()); app.use(connect.methodOverride()); app.use(connect.cookieDecoder()); app.use(express.logger()); app.use(express.methodOverride()); app.use(express.cookieDecoder());
For documentation on creating Connect middleware visit [Middleware Authoring](http://extjs.github.com/Connect/#Middleware-Authoring).
### Running Applications119 unmodified linesExpand all