Skip to content

Commit

Permalink
feat(hooks): add a hook to the request handler (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie authored May 31, 2018
1 parent d8d131e commit ade11be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"parseurl": "^1.3.1",
"pg": ">=6.1.0 <8",
"pg-connection-string": "^0.1.3",
"pg-sql2": "2.0.0",
"pg-sql2": "2.1.0",
"postgraphile-core": "4.0.0-beta.7.2",
"send": "^0.16.1",
"tslib": "^1.5.0"
Expand Down
11 changes: 10 additions & 1 deletion src/postgraphile/http/createPostGraphileHttpRequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,16 @@ export default function createPostGraphileHttpRequestHandler(options) {
* @param {IncomingMessage} req
* @param {ServerResponse} res
*/
const requestHandler = async (req, res, next) => {
const requestHandler = async (incomingReq, res, next) => {
// You can use this hook either to modify the incoming request or to tell
// PostGraphile not to handle the request further (return null). NOTE: if
// you return `null` from this hook then you are also responsible for
// calling `next()` (should that be required).
const req = pluginHook('postgraphile:http:handler', incomingReq, {options, res, next})
if (req == null) {
return
}

// Add our CORS headers to be good web citizens (there are perf
// implications though so be careful!)
//
Expand Down
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5921,6 +5921,12 @@ [email protected]:
dependencies:
debug ">=2 <3"

[email protected]:
version "2.1.0"
resolved "https://registry.yarnpkg.com/pg-sql2/-/pg-sql2-2.1.0.tgz#f86978278451482099e4f8e8db8b7486ecb67e3f"
dependencies:
debug ">=2 <3"

pg-types@~1.12.1:
version "1.12.1"
resolved "https://registry.yarnpkg.com/pg-types/-/pg-types-1.12.1.tgz#d64087e3903b58ffaad279e7595c52208a14c3d2"
Expand Down

0 comments on commit ade11be

Please sign in to comment.