fix examples for express 4 (separate middleware)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
close #1947
authored by Roman Shtylman · committed by Roman Shtylman · parent a0e6bb5 · Browse files · 6 files·+27 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+27 added−17 removed
- other:+27 added−17 removed
Provenance
- Commit
f1315b9- Tree
27b1e1d- Author
Roman Shtylman <shtylman@gmail.com>- Committer
Roman Shtylman <shtylman@gmail.com>- Parent
a0e6bb5
6 files changed+27 added−17 removed
modified:examples/jade/index.js+6 added-2 removed
10 unmodified lines111213141515171617181918 unmodified lines38394041424344454647484910 unmodified lines
// setup middleware
var app = express();app.use(app.router);app.use(express.static(pub));app.use(express.errorHandler());
// Optional since express defaults to CWD/views
app.set('views', __dirname + '/views');18 unmodified linesapp.get('/', function(req, res){ res.render('users', { users: users });});
// change this to a better error handler in your code// sending stacktrace to users in production is not goodapp.use(function(err, req, res, next) { res.send(err.stack);});
app.listen(3000);console.log('Express app started on port 3000');modified:examples/multipart/index.js+4 added-5 removed
2 unmodified lines3456789101111121312131415166 unmodified lines2324252628272829303132333436352 unmodified lines * Module dependencies. */
var express = require('../..') , bodyParser = require('body-parser') , format = require('util').format;
var app = module.exports = express()
// bodyParser in connect 2.x uses node-formidable to parse // the multipart form data.app.use(express.bodyParser())app.use(bodyParser())
app.get('/', function(req, res){ res.send('<form method="post" enctype="multipart/form-data">' + '<p>Title: <input type="text" name="title" /></p>'6 unmodified lines // the uploaded file can be found as `req.files.image` and the // title field as `req.body.title` res.send(format('\nuploaded %s (%d Kb) to %s as %s' , req.files.image.name , req.files.image.size / 1024 | 0 , req.files.image.size / 1024 | 0 , req.files.image.path , req.body.title));});
if (!module.parent) { app.listen(3000); console.log('Express started on port 3000');}No newline at end of file}modified:examples/session/index.js+4 added-2 removed
2 unmodified lines345678910111213141315161716181920212210 unmodified lines2 unmodified lines// $ npm install redis// $ redis-server
var express = require('../..');var cookieParser = require('cookie-parser');var session = require('express-session');
var app = express();
// Required by session() middleware// pass the secret for signed cookies// (required by session())app.use(express.cookieParser('keyboard cat'));app.use(cookieParser('keyboard cat'));
// Populates req.sessionapp.use(express.session());app.use(session());
app.get('/', function(req, res){ var body = ''; if (req.session.views) {10 unmodified linesmodified:examples/session/redis.js+8 added-5 removed
12345678679101112131114151617181619202119222324252610 unmodified lines
var express = require('../..');var logger = require('morgan');var cookieParser = require('cookie-parser');var session = require('express-session');
// pass the express to the connect redis module// allowing it to inherit from express.session.Storevar RedisStore = require('connect-redis')(express);// allowing it to inherit from session.Storevar RedisStore = require('connect-redis')(session);
var app = express();
app.use(express.logger('dev'));app.use(logger('dev'));
// Required by session() middleware// pass the secret for signed cookies// (required by session())app.use(express.cookieParser('keyboard cat'));app.use(cookieParser('keyboard cat'));
// Populates req.sessionapp.use(express.session({ store: new RedisStore }));app.use(session({ store: new RedisStore }));
app.get('/', function(req, res){ var body = ''; if (req.session.views) {10 unmodified linesmodified:examples/vhost/index.js+3 added-2 removed
2 unmodified lines3456789101128 unmodified lines40414243434444454647482 unmodified lines */
var express = require('../..');var logger = require('morgan');var vhost = require('vhost');
/*edit /etc/hosts:
28 unmodified lines// Vhost app
var app = express();
app.use(express.vhost('*.example.com', redirect)) // Serves all subdomains via Redirect appapp.use(express.vhost('example.com', main)); // Serves top level domain via Main server app app.use(vhost('*.example.com', redirect)) // Serves all subdomains via Redirect appapp.use(vhost('example.com', main)); // Serves top level domain via Main server app
app.listen(3000);console.log('Express app started on port 3000');modified:package.json+2 added-1 removed
49 unmodified lines50 "body-parser": "1.0.0",51 "cookie-parser": "1.0.1",52 "static-favicon": "1.0.0",53 "express-session": "1.0.1",54- "morgan": "1.0.0"54+ "morgan": "1.0.0",55+ "vhost": "1.0.0"56 },57 "keywords": [58 "express",59 "framework",18 unmodified lines