Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Array.filter with Array.splice, to prevent the creation of a new... #184

Closed
wants to merge 3 commits into from
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
8 changes: 7 additions & 1 deletion lib/instrumentation/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,13 @@ module.exports = function initialize(agent, express) {
function removeInterceptor(app) {
if (app.stack && app.stack.length) {
// Remove our custom error handler.
app.stack = app.stack.filter(function cb_filter(m) { return m !== interceptor })
// Move backwards so the index is not affected by the splicing.
var i = app.stack.length - 1;
for (; i >= 0; i--) {
if (app.stack[i] === interceptor) {
app.stack.splice(i, 1);
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"connect": "*",
"cover": "*",
"express": "*",
"express-enrouten": "^1.1.1",
"generic-pool": "*",
"glob": "~3.2.9",
"hapi": "*",
Expand Down
43 changes: 43 additions & 0 deletions test/versioned/express4-ejs/express4-express-enrouten.tap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* This test checks for regressions on the route stack manipulation for Express apps.
*/
'use strict'

var path = require('path')
, test = require('tap').test
, request = require('request')
, helper = require('../../lib/agent_helper.js')


test("Express 4 + express-enrouten compatibility test", function (t) {
t.plan(2)

var agent = helper.instrumentMockedAgent()
, express = require('express')
, enrouten= require('express-enrouten')
, app = express()
, server = require('http').createServer(app)

app.use(enrouten({directory:'./fixtures'}));

this.tearDown(function cb_tearDown() {
server.close(function cb_close() {
helper.unloadAgent(agent)
})
})


//New Relic + express-enrouten used to have a bug, where any routes after the first one would be lost.
server.listen(8080, function () {
request.get('http://localhost:8080/',
function (error, res, body) {

t.equal(res.statusCode, 200, 'First Route loaded')
})

request.get('http://localhost:8080/foo',
function (error, res, body) {
t.equal(res.statusCode, 200, 'Second Route loaded')
})
})
});
19 changes: 19 additions & 0 deletions test/versioned/express4-ejs/fixtures/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Created by lmarkus on 11/24/14.
*/
var routes = function(router){

router.get('/',function(req,res){
res.send('kraken');
res.end();

});

router.get('/foo',function(req,res){
res.send('kraken-foo');
res.end();
})

};

module.exports = routes;