Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

`createServer()` should accept middleware. #520

Closed
wants to merge 1 commit into from

3 participants

@stephank

createServer used to accept middleware, to be mounted at /. In fact, a lot of the included examples try to use this functionality, but are right now broken.

@tj
Owner
tj commented

In 2.x we can break a few little things like this, it was a bad idea from the beginning, you can't manipulate it progressively and you have no access to mounting so it's inevitable that you'll have to break it out into .use() calls at some point

@stephank

I concur, but then, should the examples be fixed instead? I'm thinking there's no real loss in accepting middleware in createServer, and we keep a small bit of backwards compat.

@tj
Owner
tj commented

yup they definitely need updates, i only had time to update the session ones since i was testing stuff anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 28, 2012
  1. @stephank
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 1 deletion.
  1. +4 −1 lib/connect.js
  2. +12 −0 test/mounting.js
View
5 lib/connect.js
@@ -61,7 +61,10 @@ function createServer() {
utils.merge(app, proto);
utils.merge(app, EventEmitter.prototype);
app.route = '/';
- app.stack = [].slice.apply(arguments);
+ app.stack = [];
+ [].forEach.call(arguments, function(fn) {
+ app.use(fn);
+ });
return app;
};
View
12 test/mounting.js
@@ -2,6 +2,18 @@
var connect = require('../')
, http = require('http');
+describe('createServer()', function(){
+ it('should accept middleware', function(done){
+ var app = connect(function(req, res, next) {
+ res.end('blog');
+ });
+
+ app.request()
+ .get('/')
+ .expect('blog', done);
+ });
+});
+
describe('app.use()', function(){
var app;
Something went wrong with that request. Please try again.