Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
5.x
===

This incorporates all changes after 4.13.1 up to 4.14.0.

5.0.0-alpha.2 / 2015-07-06
==========================

This is the second Express 5.0 alpha release, based off 4.13.1 and includes
changes from 5.0.0-alpha.1.

* remove:
- `app.param(fn)`
- `req.param()` -- use `req.params`, `req.body`, or `req.query` instead
* change:
- `res.render` callback is always async, even for sync view engines
- The leading `:` character in `name` for `app.param(name, fn)` is no longer removed
- Use `router` module for routing
- Use `path-is-absolute` module for absolute path detection

5.0.0-alpha.1 / 2014-11-06
==========================

This is the first Express 5.0 alpha release, based off 4.10.1.

* remove:
- `app.del` - use `app.delete`
- `req.acceptsCharset` - use `req.acceptsCharsets`
- `req.acceptsEncoding` - use `req.acceptsEncodings`
- `req.acceptsLanguage` - use `req.acceptsLanguages`
- `res.json(obj, status)` signature - use `res.json(status, obj)`
- `res.jsonp(obj, status)` signature - use `res.jsonp(status, obj)`
- `res.send(body, status)` signature - use `res.send(status, body)`
- `res.send(status)` signature - use `res.sendStatus(status)`
- `res.sendfile` - use `res.sendFile` instead
- `express.query` middleware
* change:
- `req.host` now returns host (`hostname:port`) - use `req.hostname` for only hostname
- `req.query` is now a getter instead of a plain property
* add:
- `app.router` is a reference to the base router

4.14.0 / 2016-06-16
===================

Expand Down
4 changes: 2 additions & 2 deletions examples/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ app.get('/', function(req, res){
* GET search for :query.
*/

app.get('/search/:query?', function(req, res){
app.get('/search/:query?', function(req, res, next){
var query = req.params.query;
db.smembers(query, function(err, vals){
if (err) return res.send(500);
if (err) return next(err);
res.send(vals);
});
});
Expand Down
8 changes: 5 additions & 3 deletions examples/static-files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var express = require('../..');
var path = require('path');
var logger = require('morgan');
var app = express();

Expand All @@ -16,25 +17,26 @@ app.use(logger('dev'));
// that you pass it. In this case "GET /js/app.js"
// will look for "./public/js/app.js".

app.use(express.static(__dirname + '/public'));
app.use(express.static(path.join(__dirname, 'public')));

// if you wanted to "prefix" you may use
// the mounting feature of Connect, for example
// "GET /static/js/app.js" instead of "GET /js/app.js".
// The mount-path "/static" is simply removed before
// passing control to the express.static() middleware,
// thus it serves the file correctly by ignoring "/static"
app.use('/static', express.static(__dirname + '/public'));
app.use('/static', express.static(path.join(__dirname, 'public')));

// if for some reason you want to serve files from
// several directories, you can use express.static()
// multiple times! Here we're passing "./public/css",
// this will allow "GET /style.css" instead of "GET /css/style.css":
app.use(express.static(__dirname + '/public/css'));
app.use(express.static(path.join(__dirname, 'public', 'css')));

app.listen(3000);
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');

98 changes: 42 additions & 56 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,17 @@
*/

var finalhandler = require('finalhandler');
var Router = require('./router');
var methods = require('methods');
var middleware = require('./middleware/init');
var query = require('./middleware/query');
var debug = require('debug')('express:application');
var View = require('./view');
var http = require('http');
var compileETag = require('./utils').compileETag;
var compileQueryParser = require('./utils').compileQueryParser;
var compileTrust = require('./utils').compileTrust;
var deprecate = require('depd')('express');
var flatten = require('array-flatten');
var merge = require('utils-merge');
var resolve = require('path').resolve;
var Router = require('router');
var slice = Array.prototype.slice;

/**
Expand All @@ -54,11 +51,29 @@ var trustProxyDefaultSymbol = '@@symbol:trust_proxy_default';
*/

app.init = function init() {
var router = null;

this.cache = {};
this.engines = {};
this.settings = {};

this.defaultConfiguration();

// Setup getting to lazily add base router
Object.defineProperty(this, 'router', {
configurable: true,
enumerable: true,
get: function getrouter() {
if (router === null) {
router = new Router({
caseSensitive: this.enabled('case sensitive routing'),
strict: this.enabled('strict routing')
});
}

return router;
}
});
};

/**
Expand Down Expand Up @@ -117,32 +132,6 @@ app.defaultConfiguration = function defaultConfiguration() {
if (env === 'production') {
this.enable('view cache');
}

Object.defineProperty(this, 'router', {
get: function() {
throw new Error('\'app.router\' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.');
}
});
};

/**
* lazily adds the base router if it has not yet been added.
*
* We cannot add the base router in the defaultConfiguration because
* it reads app settings which might be set after that has run.
*
* @private
*/
app.lazyrouter = function lazyrouter() {
if (!this._router) {
this._router = new Router({
caseSensitive: this.enabled('case sensitive routing'),
strict: this.enabled('strict routing')
});

this._router.use(query(this.get('query parser fn')));
this._router.use(middleware.init(this));
}
};

/**
Expand All @@ -155,22 +144,31 @@ app.lazyrouter = function lazyrouter() {
*/

app.handle = function handle(req, res, callback) {
var router = this._router;

// final handler
var done = callback || finalhandler(req, res, {
env: this.get('env'),
onerror: logerror.bind(this)
});

// no routes
if (!router) {
debug('no routes defined on app');
done();
return;
// set powered by header
if (this.enabled('x-powered-by')) {
res.setHeader('X-Powered-By', 'Express');
}

router.handle(req, res, done);
// set circular references
req.res = res;
res.req = req;

// alter the prototypes
req.__proto__ = this.request;
res.__proto__ = this.response;

// setup locals
if (!res.locals) {
res.locals = Object.create(null);
}

this.router.handle(req, res, done);
};

/**
Expand Down Expand Up @@ -209,9 +207,8 @@ app.use = function use(fn) {
throw new TypeError('app.use() requires middleware functions');
}

// setup router
this.lazyrouter();
var router = this._router;
// get router
var router = this.router;

fns.forEach(function (fn) {
// non-express app
Expand Down Expand Up @@ -251,8 +248,7 @@ app.use = function use(fn) {
*/

app.route = function route(path) {
this.lazyrouter();
return this._router.route(path);
return this.router.route(path);
};

/**
Expand Down Expand Up @@ -318,8 +314,6 @@ app.engine = function engine(ext, fn) {
*/

app.param = function param(name, fn) {
this.lazyrouter();

if (Array.isArray(name)) {
for (var i = 0; i < name.length; i++) {
this.param(name[i], fn);
Expand All @@ -328,7 +322,7 @@ app.param = function param(name, fn) {
return this;
}

this._router.param(name, fn);
this.router.param(name, fn);

return this;
};
Expand Down Expand Up @@ -475,9 +469,7 @@ methods.forEach(function(method){
return this.set(path);
}

this.lazyrouter();

var route = this._router.route(path);
var route = this.route(path);
route[method].apply(route, slice.call(arguments, 1));
return this;
};
Expand All @@ -494,9 +486,7 @@ methods.forEach(function(method){
*/

app.all = function all(path) {
this.lazyrouter();

var route = this._router.route(path);
var route = this.route(path);
var args = slice.call(arguments, 1);

for (var i = 0; i < methods.length; i++) {
Expand All @@ -506,10 +496,6 @@ app.all = function all(path) {
return this;
};

// del -> delete alias

app.del = deprecate.function(app.delete, 'app.del: Use app.delete instead');

/**
* Render the given view `name` name with `options`
* and a callback accepting an error and the
Expand Down
7 changes: 3 additions & 4 deletions lib/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
var EventEmitter = require('events').EventEmitter;
var mixin = require('merge-descriptors');
var proto = require('./application');
var Route = require('./router/route');
var Router = require('./router');
var Router = require('router');
var req = require('./request');
var res = require('./response');

Expand Down Expand Up @@ -59,14 +58,13 @@ exports.response = res;
* Expose constructors.
*/

exports.Route = Route;
exports.Route = Router.Route;
exports.Router = Router;

/**
* Expose middleware
*/

exports.query = require('./middleware/query');
exports.static = require('serve-static');

/**
Expand All @@ -93,6 +91,7 @@ exports.static = require('serve-static');
'limit',
'multipart',
'staticCache',
'query',
].forEach(function (name) {
Object.defineProperty(exports, name, {
get: function () {
Expand Down
Loading