{"action":"created","comment":{"url":"https://api.github.com/repos/GPII/gpii-express/pulls/comments/60220016","id":60220016,"diff_hunk":"@@ -0,0 +1,85 @@\n+/*\n+\n+    A router which passes a request to different handlers based on what the request accepts.  See the documentation for\n+    details:\n+\n+    https://github.com/GPII/gpii-express/blob/master/docs/contentAwareRouter.md\n+\n+ */\n+\"use strict\";\n+var fluid = require(\"infusion\");\n+var gpii  = fluid.registerNamespace(\"gpii\");\n+\n+require(\"./requestAwareMiddleware\");\n+\n+fluid.registerNamespace(\"gpii.express.middleware.contentAware\");\n+\n+/**\n+ * \n+ * Handle all traffic routed to us.  Locate an appropriate handler if possible, return a clear error if not.\n+ * \n+ * @param that {Object} The router component itself.\n+ * @param request {Object} The Express {Request} object.\n+ * @param response {Object} The Express {Response} object.\n+ * \n+ */\n+gpii.express.middleware.contentAware.delegateToHandler = function (that, request, response, next) {\n+    var handlerGrades = gpii.express.middleware.contentAware.getHandlerGradesByContentType(that, request);\n+    if (handlerGrades) {\n+        that.events.onRequest.fire(request, response, handlerGrades);\n+    }\n+    else {\n+        next({ isError: true, message: that.options.messages.noHandlerFound });\n+    }\n+};\n+\n+/**\n+ * \n+ * Return the first matching handler that matches the `request` object's `accept` header.  Handlers are sorted by \n+ * priority before they are evaluated.\n+ * \n+ * @param that {Object} The router component itself.\n+ * @param request {Object} The Express {Request} object.\n+ * @returns {Array} An array of handler grades that will be used to create our handler.\n+ * \n+ */\n+gpii.express.middleware.contentAware.getHandlerGradesByContentType = function (that, request) {\n+    var orderedHandlers = gpii.express.orderByPriority(that.options.handlers);\n+    var matchingHandler = fluid.find(orderedHandlers, function (value) {\n+        return Boolean(value.contentType && request.accepts(value.contentType)) ? value : undefined;\n+    });\n+\n+    return matchingHandler ? matchingHandler.handlerGrades : undefined;\n+};\n+\n+fluid.defaults(\"gpii.express.middleware.contentAware\", {\n+    gradeNames: [\"gpii.express.middleware\"],\n+    timeout: 5000,\n+    messages: {\n+        noHandlerFound: \"Could not find an appropriate handler for the content types you accept.\"\n+    },\n+    distributeOptions: {\n+        source: \"{that}.options.timeout\",\n+        target: \"{that gpii.express.handler}.options.timeout\"\n+    },\n+    events: {\n+        onRequest: null\n+    },\n+    dynamicComponents: {","path":"src/js/contentAwareMiddleware.js","position":null,"original_position":68,"commit_id":"7de98f82770c97fa2b2f06cdbb34a5362aa47d32","original_commit_id":"cbbd36fed5bf1fd6fe641d6cb5420cf17b239a12","user":{"login":"the-t-in-rtf","id":5765222,"avatar_url":"https://avatars.githubusercontent.com/u/5765222?v=3","gravatar_id":"","url":"https://api.github.com/users/the-t-in-rtf","html_url":"https://github.com/the-t-in-rtf","followers_url":"https://api.github.com/users/the-t-in-rtf/followers","following_url":"https://api.github.com/users/the-t-in-rtf/following{/other_user}","gists_url":"https://api.github.com/users/the-t-in-rtf/gists{/gist_id}","starred_url":"https://api.github.com/users/the-t-in-rtf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/the-t-in-rtf/subscriptions","organizations_url":"https://api.github.com/users/the-t-in-rtf/orgs","repos_url":"https://api.github.com/users/the-t-in-rtf/repos","events_url":"https://api.github.com/users/the-t-in-rtf/events{/privacy}","received_events_url":"https://api.github.com/users/the-t-in-rtf/received_events","type":"User","site_admin":false},"body":"Yes, I would have assumed it would work until I had clear evidence to the contrary.  Wrapping options in an enclosing object didn't help.  Anyway, I have only to uncomment a few lines to step through it together in our next pairing session.","created_at":"2016-04-19T12:21:42Z","updated_at":"2016-04-19T12:21:42Z","html_url":"https://github.com/GPII/gpii-express/pull/20#discussion_r60220016","pull_request_url":"https://api.github.com/repos/GPII/gpii-express/pulls/20","_links":{"self":{"href":"https://api.github.com/repos/GPII/gpii-express/pulls/comments/60220016"},"html":{"href":"https://github.com/GPII/gpii-express/pull/20#discussion_r60220016"},"pull_request":{"href":"https://api.github.com/repos/GPII/gpii-express/pulls/20"}}},"pull_request":{"url":"https://api.github.com/repos/GPII/gpii-express/pulls/20","id":62883318,"html_url":"https://github.com/GPII/gpii-express/pull/20","diff_url":"https://github.com/GPII/gpii-express/pull/20.diff","patch_url":"https://github.com/GPII/gpii-express/pull/20.patch","issue_url":"https://api.github.com/repos/GPII/gpii-express/issues/20","number":20,"state":"open","locked":false,"title":"GPII-1682: Update \"static\" handler to support multiple content directories...","user":{"login":"the-t-in-rtf","id":5765222,"avatar_url":"https://avatars.githubusercontent.com/u/5765222?v=3","gravatar_id":"","url":"https://api.github.com/users/the-t-in-rtf","html_url":"https://github.com/the-t-in-rtf","followers_url":"https://api.github.com/users/the-t-in-rtf/followers","following_url":"https://api.github.com/users/the-t-in-rtf/following{/other_user}","gists_url":"https://api.github.com/users/the-t-in-rtf/gists{/gist_id}","starred_url":"https://api.github.com/users/the-t-in-rtf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/the-t-in-rtf/subscriptions","organizations_url":"https://api.github.com/users/the-t-in-rtf/orgs","repos_url":"https://api.github.com/users/the-t-in-rtf/repos","events_url":"https://api.github.com/users/the-t-in-rtf/events{/privacy}","received_events_url":"https://api.github.com/users/the-t-in-rtf/received_events","type":"User","site_admin":false},"body":"See [GPII-1682](https://issues.gpii.net/browse/GPII-1682) for details.","created_at":"2016-03-15T10:27:57Z","updated_at":"2016-04-19T12:21:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"612cacb50b0656add1104aa3eaf6c0b1b8b8d163","assignee":{"login":"amb26","id":561418,"avatar_url":"https://avatars.githubusercontent.com/u/561418?v=3","gravatar_id":"","url":"https://api.github.com/users/amb26","html_url":"https://github.com/amb26","followers_url":"https://api.github.com/users/amb26/followers","following_url":"https://api.github.com/users/amb26/following{/other_user}","gists_url":"https://api.github.com/users/amb26/gists{/gist_id}","starred_url":"https://api.github.com/users/amb26/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amb26/subscriptions","organizations_url":"https://api.github.com/users/amb26/orgs","repos_url":"https://api.github.com/users/amb26/repos","events_url":"https://api.github.com/users/amb26/events{/privacy}","received_events_url":"https://api.github.com/users/amb26/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/GPII/gpii-express/pulls/20/commits","review_comments_url":"https://api.github.com/repos/GPII/gpii-express/pulls/20/comments","review_comment_url":"https://api.github.com/repos/GPII/gpii-express/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GPII/gpii-express/issues/20/comments","statuses_url":"https://api.github.com/repos/GPII/gpii-express/statuses/7de98f82770c97fa2b2f06cdbb34a5362aa47d32","head":{"label":"the-t-in-rtf:GPII-1682","ref":"GPII-1682","sha":"7de98f82770c97fa2b2f06cdbb34a5362aa47d32","user":{"login":"the-t-in-rtf","id":5765222,"avatar_url":"https://avatars.githubusercontent.com/u/5765222?v=3","gravatar_id":"","url":"https://api.github.com/users/the-t-in-rtf","html_url":"https://github.com/the-t-in-rtf","followers_url":"https://api.github.com/users/the-t-in-rtf/followers","following_url":"https://api.github.com/users/the-t-in-rtf/following{/other_user}","gists_url":"https://api.github.com/users/the-t-in-rtf/gists{/gist_id}","starred_url":"https://api.github.com/users/the-t-in-rtf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/the-t-in-rtf/subscriptions","organizations_url":"https://api.github.com/users/the-t-in-rtf/orgs","repos_url":"https://api.github.com/users/the-t-in-rtf/repos","events_url":"https://api.github.com/users/the-t-in-rtf/events{/privacy}","received_events_url":"https://api.github.com/users/the-t-in-rtf/received_events","type":"User","site_admin":false},"repo":{"id":30924618,"name":"gpii-express","full_name":"the-t-in-rtf/gpii-express","owner":{"login":"the-t-in-rtf","id":5765222,"avatar_url":"https://avatars.githubusercontent.com/u/5765222?v=3","gravatar_id":"","url":"https://api.github.com/users/the-t-in-rtf","html_url":"https://github.com/the-t-in-rtf","followers_url":"https://api.github.com/users/the-t-in-rtf/followers","following_url":"https://api.github.com/users/the-t-in-rtf/following{/other_user}","gists_url":"https://api.github.com/users/the-t-in-rtf/gists{/gist_id}","starred_url":"https://api.github.com/users/the-t-in-rtf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/the-t-in-rtf/subscriptions","organizations_url":"https://api.github.com/users/the-t-in-rtf/orgs","repos_url":"https://api.github.com/users/the-t-in-rtf/repos","events_url":"https://api.github.com/users/the-t-in-rtf/events{/privacy}","received_events_url":"https://api.github.com/users/the-t-in-rtf/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/the-t-in-rtf/gpii-express","description":"A fluid module to load express.js","fork":true,"url":"https://api.github.com/repos/the-t-in-rtf/gpii-express","forks_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/forks","keys_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/keys{/key_id}","collaborators_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/teams","hooks_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/hooks","issue_events_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/issues/events{/number}","events_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/events","assignees_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/assignees{/user}","branches_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/branches{/branch}","tags_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/tags","blobs_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/git/refs{/sha}","trees_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/git/trees{/sha}","statuses_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/statuses/{sha}","languages_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/languages","stargazers_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/stargazers","contributors_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/contributors","subscribers_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/subscribers","subscription_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/subscription","commits_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/commits{/sha}","git_commits_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/git/commits{/sha}","comments_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/comments{/number}","issue_comment_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/issues/comments{/number}","contents_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/contents/{+path}","compare_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/compare/{base}...{head}","merges_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/merges","archive_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/downloads","issues_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/issues{/number}","pulls_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/pulls{/number}","milestones_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/milestones{/number}","notifications_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/labels{/name}","releases_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/releases{/id}","deployments_url":"https://api.github.com/repos/the-t-in-rtf/gpii-express/deployments","created_at":"2015-02-17T16:02:26Z","updated_at":"2016-02-08T10:02:27Z","pushed_at":"2016-04-19T12:16:01Z","git_url":"git://github.com/the-t-in-rtf/gpii-express.git","ssh_url":"git@github.com:the-t-in-rtf/gpii-express.git","clone_url":"https://github.com/the-t-in-rtf/gpii-express.git","svn_url":"https://github.com/the-t-in-rtf/gpii-express","homepage":null,"size":392,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"GPII:master","ref":"master","sha":"2986297e337d24f2ce92cbda66403b82e02618d0","user":{"login":"GPII","id":1343050,"avatar_url":"https://avatars.githubusercontent.com/u/1343050?v=3","gravatar_id":"","url":"https://api.github.com/users/GPII","html_url":"https://github.com/GPII","followers_url":"https://api.github.com/users/GPII/followers","following_url":"https://api.github.com/users/GPII/following{/other_user}","gists_url":"https://api.github.com/users/GPII/gists{/gist_id}","starred_url":"https://api.github.com/users/GPII/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GPII/subscriptions","organizations_url":"https://api.github.com/users/GPII/orgs","repos_url":"https://api.github.com/users/GPII/repos","events_url":"https://api.github.com/users/GPII/events{/privacy}","received_events_url":"https://api.github.com/users/GPII/received_events","type":"Organization","site_admin":false},"repo":{"id":30625709,"name":"gpii-express","full_name":"GPII/gpii-express","owner":{"login":"GPII","id":1343050,"avatar_url":"https://avatars.githubusercontent.com/u/1343050?v=3","gravatar_id":"","url":"https://api.github.com/users/GPII","html_url":"https://github.com/GPII","followers_url":"https://api.github.com/users/GPII/followers","following_url":"https://api.github.com/users/GPII/following{/other_user}","gists_url":"https://api.github.com/users/GPII/gists{/gist_id}","starred_url":"https://api.github.com/users/GPII/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GPII/subscriptions","organizations_url":"https://api.github.com/users/GPII/orgs","repos_url":"https://api.github.com/users/GPII/repos","events_url":"https://api.github.com/users/GPII/events{/privacy}","received_events_url":"https://api.github.com/users/GPII/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GPII/gpii-express","description":"A fluid module to load express.js","fork":false,"url":"https://api.github.com/repos/GPII/gpii-express","forks_url":"https://api.github.com/repos/GPII/gpii-express/forks","keys_url":"https://api.github.com/repos/GPII/gpii-express/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GPII/gpii-express/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GPII/gpii-express/teams","hooks_url":"https://api.github.com/repos/GPII/gpii-express/hooks","issue_events_url":"https://api.github.com/repos/GPII/gpii-express/issues/events{/number}","events_url":"https://api.github.com/repos/GPII/gpii-express/events","assignees_url":"https://api.github.com/repos/GPII/gpii-express/assignees{/user}","branches_url":"https://api.github.com/repos/GPII/gpii-express/branches{/branch}","tags_url":"https://api.github.com/repos/GPII/gpii-express/tags","blobs_url":"https://api.github.com/repos/GPII/gpii-express/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GPII/gpii-express/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GPII/gpii-express/git/refs{/sha}","trees_url":"https://api.github.com/repos/GPII/gpii-express/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GPII/gpii-express/statuses/{sha}","languages_url":"https://api.github.com/repos/GPII/gpii-express/languages","stargazers_url":"https://api.github.com/repos/GPII/gpii-express/stargazers","contributors_url":"https://api.github.com/repos/GPII/gpii-express/contributors","subscribers_url":"https://api.github.com/repos/GPII/gpii-express/subscribers","subscription_url":"https://api.github.com/repos/GPII/gpii-express/subscription","commits_url":"https://api.github.com/repos/GPII/gpii-express/commits{/sha}","git_commits_url":"https://api.github.com/repos/GPII/gpii-express/git/commits{/sha}","comments_url":"https://api.github.com/repos/GPII/gpii-express/comments{/number}","issue_comment_url":"https://api.github.com/repos/GPII/gpii-express/issues/comments{/number}","contents_url":"https://api.github.com/repos/GPII/gpii-express/contents/{+path}","compare_url":"https://api.github.com/repos/GPII/gpii-express/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GPII/gpii-express/merges","archive_url":"https://api.github.com/repos/GPII/gpii-express/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GPII/gpii-express/downloads","issues_url":"https://api.github.com/repos/GPII/gpii-express/issues{/number}","pulls_url":"https://api.github.com/repos/GPII/gpii-express/pulls{/number}","milestones_url":"https://api.github.com/repos/GPII/gpii-express/milestones{/number}","notifications_url":"https://api.github.com/repos/GPII/gpii-express/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GPII/gpii-express/labels{/name}","releases_url":"https://api.github.com/repos/GPII/gpii-express/releases{/id}","deployments_url":"https://api.github.com/repos/GPII/gpii-express/deployments","created_at":"2015-02-11T02:12:46Z","updated_at":"2016-01-27T17:08:54Z","pushed_at":"2016-04-19T12:16:01Z","git_url":"git://github.com/GPII/gpii-express.git","ssh_url":"git@github.com:GPII/gpii-express.git","clone_url":"https://github.com/GPII/gpii-express.git","svn_url":"https://github.com/GPII/gpii-express","homepage":null,"size":200,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":2,"forks":6,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GPII/gpii-express/pulls/20"},"html":{"href":"https://github.com/GPII/gpii-express/pull/20"},"issue":{"href":"https://api.github.com/repos/GPII/gpii-express/issues/20"},"comments":{"href":"https://api.github.com/repos/GPII/gpii-express/issues/20/comments"},"review_comments":{"href":"https://api.github.com/repos/GPII/gpii-express/pulls/20/comments"},"review_comment":{"href":"https://api.github.com/repos/GPII/gpii-express/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GPII/gpii-express/pulls/20/commits"},"statuses":{"href":"https://api.github.com/repos/GPII/gpii-express/statuses/7de98f82770c97fa2b2f06cdbb34a5362aa47d32"}}}}