Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
fix: ignore non-JSON API requests
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Nov 25, 2015
1 parent 6245f4e commit 2705bb1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ internals.onPreHandler = function (request, reply) {
return reply.continue();
};

if(internals.isntJsonApiRequest(request)) {
return reply.continue();
}

/**
* Accept parsing is complicated and there wasn't a library I could
* quickly find to parse them. At the expense of missing out
Expand Down Expand Up @@ -58,6 +62,10 @@ internals.onPreResponse = function (request, reply) {
return reply.continue();
}

if(internals.isntJsonApiRequest(request)) {
return reply.continue();
}

if (response.isBoom) {
var error = {
title: response.output.payload.error,
Expand All @@ -78,6 +86,18 @@ internals.onPreResponse = function (request, reply) {
return reply.continue();
};

internals.isntJsonApiRequest = function (request) {
if(!request.headers.accept) {
return true;
}

if (request.headers.accept.indexOf('application/vnd.api+json') === -1) {
return true;
}

return false;
}

// Exports

exports.register = function (plugin, options, done) {
Expand Down

0 comments on commit 2705bb1

Please sign in to comment.