Permalink
Browse files

remove last pieces of connect dependency

- copy over patch.js to shim ServerResponse
- bundle `static` middleware
  • Loading branch information...
1 parent 6a7363e commit 1396e0855d1f7cf0ef86913e74c262bb9ade7e7e @defunctzombie defunctzombie committed Feb 16, 2014
View
@@ -8,6 +8,7 @@
- `app.router` - is removed
- `req.accepted*` - use `req.accepts*()` instead
- `res.location` - relative URL resolution is removed
+ - all bundled middleware except `static`
* change:
- `app.route` -> `app.mountpath` when mounting an express app in another express app
- `json spaces` no longer enabled by default in development
View
@@ -3,7 +3,10 @@
*/
var express = require('../..')
- , hash = require('./pass').hash;
+ , hash = require('./pass').hash
+ , bodyParser = require('body-parser')
+ , cookieParser = require('cookie-parser')
+ , session = require('express-session')
var app = module.exports = express();
@@ -14,9 +17,9 @@ app.set('views', __dirname + '/views');
// middleware
-app.use(express.bodyParser());
-app.use(express.cookieParser('shhhh, very secret'));
-app.use(express.session());
+app.use(bodyParser());
+app.use(cookieParser('shhhh, very secret'));
+app.use(session());
// Session-persisted message middleware
@@ -1,5 +1,6 @@
var express = require('../..')
+ , logger = require('morgan')
, app = express();
app.set('views', __dirname);
@@ -14,11 +15,11 @@ while (n--) {
pets.push({ name: 'Jane', age: 6, species: 'ferret' });
}
-app.use(express.logger('dev'));
+app.use(logger('dev'));
app.get('/', function(req, res){
res.render('pets', { pets: pets });
});
app.listen(3000);
-console.log('Express listening on port 3000');
+console.log('Express listening on port 3000');
@@ -4,17 +4,19 @@
*/
var express = require('../../');
+var favicon = require('static-favicon');
+var cookie-parser = require('cookie-parser');
@carchrae

carchrae Mar 21, 2014

cutnpaste fail - var cookie-parser => var cookieParser

var app = module.exports = express();
// ignore GET /favicon.ico
-app.use(express.favicon());
+app.use(favicon());
// pass a secret to cookieParser() for signed cookies
-app.use(express.cookieParser('manny is cool'));
+app.use(cookieParser('manny is cool'));
// add req.session cookie support
-app.use(express.cookieSession());
+app.use(cookieSession());
// do something with the session
app.use(count);
@@ -29,4 +31,4 @@ function count(req, res) {
if (!module.parent) {
app.listen(3000);
console.log('Express server listening on port 3000');
-}
+}
View
@@ -4,28 +4,32 @@
*/
var express = require('../../')
- , app = module.exports = express();
+ , app = module.exports = express()
+ , favicon = require('static-favicon')
+ , logger = require('morgan')
+ , cookieParser = require('cookie-parser')
+ , bodyParser = require('body-parser')
// add favicon() before logger() so
// GET /favicon.ico requests are not
// logged, because this middleware
// reponds to /favicon.ico and does not
// call next()
-app.use(express.favicon());
+app.use(favicon());
// custom log format
if ('test' != process.env.NODE_ENV)
- app.use(express.logger(':method :url'));
+ app.use(logger(':method :url'));
// parses request cookies, populating
// req.cookies and req.signedCookies
-// when the secret is passed, used
+// when the secret is passed, used
// for signing the cookies.
-app.use(express.cookieParser('my secret here'));
+app.use(cookieParser('my secret here'));
// parses json, x-www-form-urlencoded, and multipart/form-data
-app.use(express.bodyParser());
+app.use(bodyParser());
app.get('/', function(req, res){
if (req.cookies.remember) {
@@ -51,4 +55,4 @@ app.post('/', function(req, res){
if (!module.parent){
app.listen(3000);
console.log('Express started on port 3000');
-}
+}
View
@@ -3,7 +3,9 @@
*/
var express = require('../..')
+ , logger = require('morgan')
, app = express()
+ , bodyParser = require('body-parser')
, api = express();
// app middleware
@@ -12,8 +14,8 @@ app.use(express.static(__dirname + '/public'));
// api middleware
-api.use(express.logger('dev'));
-api.use(express.bodyParser());
+api.use(logger('dev'));
+api.use(bodyParser());
/**
* CORS support.
@@ -4,6 +4,8 @@
var express = require('../../')
, app = module.exports = express()
+ , logger = require('morgan')
+ , favicon = require('static-favicon')
, silent = 'test' == process.env.NODE_ENV;
// general config
@@ -21,9 +23,9 @@ if ('production' == app.settings.env) {
app.disable('verbose errors');
}
-app.use(express.favicon());
+app.use(favicon());
-silent || app.use(express.logger('dev'));
+silent || app.use(logger('dev'));
// Routes
View
@@ -4,10 +4,11 @@
*/
var express = require('../../')
+ , logger = require('morgan')
, app = module.exports = express()
, test = app.get('env') == 'test';
-if (!test) app.use(express.logger('dev'));
+if (!test) app.use(logger('dev'));
// error handling middleware have an arity of 4
// instead of the typical (req, res, next),
@@ -1,5 +1,6 @@
var express = require('../..')
+ , logger = require('morgan')
, app = express();
app.set('view engine', 'jade');
@@ -23,7 +24,7 @@ User.prototype.toJSON = function(){
}
};
-app.use(express.logger('dev'));
+app.use(logger('dev'));
// earlier on expose an object
// that we can tack properties on.
@@ -57,4 +58,4 @@ app.get('/user', function(req, res){
});
app.listen(3000);
-console.log('app listening on port 3000');
+console.log('app listening on port 3000');
View
@@ -1,4 +1,8 @@
var express = require('../..');
+var logger = require('morgan');
+var session = require('express-session');
+var cookieParser = require('cookie-parser');
+var bodyParser = require('body-parser');
var app = module.exports = express();
@@ -25,20 +29,17 @@ app.response.message = function(msg){
};
// log
-if (!module.parent) app.use(express.logger('dev'));
+if (!module.parent) app.use(logger('dev'));
// serve static files
app.use(express.static(__dirname + '/public'));
// session support
-app.use(express.cookieParser('some secret here'));
-app.use(express.session());
+app.use(cookieParser('some secret here'));
+app.use(session());
// parse request bodies (req.body)
-app.use(express.bodyParser());
-
-// support _method (PUT in forms etc)
-app.use(express.methodOverride());
+app.use(bodyParser());
// expose the "messages" local variable when views are rendered
app.use(function(req, res, next){
@@ -5,6 +5,9 @@
var express = require('../..')
, app = express()
+ , logger = require('morgan')
+ , cookieParser = require('cookie-parser')
+ , bodyParser = require('body-parser')
, site = require('./site')
, post = require('./post')
, user = require('./user');
@@ -13,10 +16,9 @@ var express = require('../..')
app.set('view engine', 'jade');
app.set('views', __dirname + '/views');
-app.use(express.logger('dev'));
-app.use(express.cookieParser());
-app.use(express.bodyParser());
-app.use(express.methodOverride());
+app.use(logger('dev'));
+app.use(cookieParser());
+app.use(bodyParser());
app.use(express.static(__dirname + '/public'));
// General
@@ -7,8 +7,6 @@ var express = require('../..');
var app = express();
-app.use(express.logger('dev'));
-
// Required by session() middleware
// pass the secret for signed cookies
// (required by session())
@@ -1,9 +1,10 @@
var express = require('../..');
+var logger = require('morgan');
var app = express();
// log requests
-app.use(express.logger('dev'));
+app.use(logger('dev'));
// express on its own has no notion
// of a "file". The express.static()
@@ -41,4 +42,4 @@ console.log('listening on port 3000');
console.log('try:');
console.log(' GET /hello.txt');
console.log(' GET /js/app.js');
-console.log(' GET /css/style.css');
+console.log(' GET /css/style.css');
View
@@ -3,6 +3,7 @@
*/
var express = require('../..');
+var logger = require('morgan');
/*
edit /etc/hosts:
@@ -16,7 +17,7 @@ edit /etc/hosts:
var main = express();
-main.use(express.logger('dev'));
+main.use(logger('dev'));
main.get('/', function(req, res){
res.send('Hello from main app!')
View
@@ -6,7 +6,8 @@ var mixin = require('utils-merge')
, escapeHtml = require('escape-html')
, Router = require('./router')
, methods = require('methods')
- , middleware = require('./middleware')
+ , middleware = require('./middleware/init')
+ , query = require('./middleware/query')
, debug = require('debug')('express:application')
, View = require('./view')
, http = require('http');
@@ -98,7 +99,7 @@ app.lazyrouter = function() {
strict: this.enabled('strict routing')
});
- this._router.use(middleware.query());
+ this._router.use(query());
this._router.use(middleware.init(this));
}
};
View
@@ -4,8 +4,7 @@
var EventEmitter = require('events').EventEmitter;
-var connect = require('connect')
- , merge = require('merge-descriptors')
+var merge = require('merge-descriptors')
, mixin = require('utils-merge')
var proto = require('./application')
@@ -14,19 +13,16 @@ var proto = require('./application')
, req = require('./request')
, res = require('./response')
+// monkey patch ServerResponse methods
+require('./patch')
+
/**
* Expose `createApplication()`.
*/
exports = module.exports = createApplication;
/**
- * Expose mime.
- */
-
-exports.mime = connect.mime;
-
-/**
* Create an express application.
*
* @return {Function}
@@ -48,13 +44,6 @@ function createApplication() {
}
/**
- * Expose connect.middleware as express.*
- * for example `express.logger` etc.
- */
-
-merge(exports, connect.middleware);
-
-/**
* Expose the prototypes.
*/
@@ -69,7 +58,8 @@ exports.response = res;
exports.Route = Route;
exports.Router = Router;
-// Error handler title
-
-exports.errorHandler.title = 'Express';
+/**
+ * Expose middleware
+ */
+exports.static = require('./middleware/static');
Oops, something went wrong.

0 comments on commit 1396e08

Please sign in to comment.