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

Attempt to fix #3399 where it crashes on route prerequisites when no domain is present #3401

Merged
merged 1 commit into from Dec 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/handler.js
Expand Up @@ -54,15 +54,15 @@ internals.prerequisites = function (request, callback) {
}, nextSet);
};

const domain = process.domain; // Save a reference to the current domain
const domain = request.domain; // Save a reference to the current domain

Items.serial(request._route._prerequisites, each, (err) => {

if (err) {
return callback(err);
}

const wrapped = domain.bind(internals.handler);
const wrapped = domain ? domain.bind(internals.handler) : internals.handler;
return wrapped(request, callback);
});
};
Expand Down
39 changes: 39 additions & 0 deletions test/handler.js
Expand Up @@ -81,6 +81,45 @@ describe('handler', () => {
expect(res.statusCode).to.equal(500);
});
});

it('works without a domain', (done) => {

const pre = function (req, reply) {

reply('pre');
};

const handler = function (req, reply) {

reply('working').code(200);
};

// this will cause the test to stop on error but is needed to test #3399
const domain = process.domain;
process.domain = undefined;

const server = new Hapi.Server({ useDomains: false });
server.connection();

server.route({
method: 'get',
path: '/',
config: {
pre: [{
method: pre
}],
handler
}
});

server.inject('/', (res) => {

expect(res.statusCode).to.equal(200);
process.domain = domain;
done();
});

});
});

describe('handler()', () => {
Expand Down