Skip to content
Myr

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

2 files+27 added−22 removed

modified:docs/guide.md+21 added-13 removed
40 unmodified lines
41Note the use of _app.router_, which can (optionally) be used to mount the application routes,42otherwise the first call to _app.{get,put,del,post}()_ will mount the routes.4344 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 });5859For internal and arbitrary settings Express provides the _set(key[, val])_, _enable(key)_, _disable(key)_ methods:60
113 unmodified lines
174175The Express _Plugin_ is no more! middleware via [Connect](http://github.com/extjs/Connect) can be176passed to _express.createServer()_ as you would with a regular Connect server. For example:177178 var connect = require('connect'),179 express = require('express');178 var express = require('express');179180 var app = express.createServer(182 connect.logger(),183 connect.bodyDecoder()181 express.logger(),182 express.bodyDecoder()183 );184185Alternatively we can _use()_ them which is useful when adding middleware within _configure()_ blocks:186188 app.use(connect.logger({ format: ':method :uri' }));187 app.use(express.logger({ format: ':method :uri' }));188189Typically with connect middleware you would _require('connect')_ like so:190191 var connect = require('connect');192 app.use(connect.logger());193194This is somewhat annoying, so express re-exports these middleware properties, however they are _identical_:195196 app.use(express.logger());197198### Error Handling199200Express provides the _app.error()_ method which receives exceptions thrown within a route,201or passed to _next(err)_. Below is an example which serves different pages based on our
41 unmodified lines
243Our apps could also utilize the Connect _errorHandler_ middleware244to report on exceptions. For example if we wish to output exceptions 245in "development" mode to _stderr_ we can use:246239 app.use(connect.errorHandler({ dumpExceptions: true }));247 app.use(express.errorHandler({ dumpExceptions: true }));248249Also during development we may want fancy html pages to show exceptions250that are passed or thrown, so we can set _showStack_ to true:251244 app.use(connect.errorHandler({ showStack: true, dumpExceptions: true }));252 app.use(express.errorHandler({ showStack: true, dumpExceptions: true }));253254The _errorHandler_ middleware also responds with _json_ if _Accept: application/json_255is present, which is useful for developing apps that rely heavily on client-side JavaScript.256
124 unmodified lines
381 - Checks urlencoded body params (_req.body_), ex: id=12382383To utilize urlencoded request bodies, _req.body_384should be an object. This can be done by using377the _connect.bodyDecoder_ middleware.385the _express.bodyDecoder_ middleware.386387### req.flash(type[, msg])388389Queue flash _msg_ of the given _type_.
295 unmodified lines
modified:docs/migrate.md+6 added-9 removed