From 478c25e90d756de57d2bf69a3f6f210d8e2250cd Mon Sep 17 00:00:00 2001 From: David Welch Date: Mon, 8 May 2017 22:44:36 -0600 Subject: [PATCH 1/3] Bugfix in routes.js 404 `,` instead of `.` - could happen to anyone ;) --- lib/routes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/routes.js b/lib/routes.js index 5d483d2..902d28f 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -180,7 +180,7 @@ var delegate = function (apicall, opts, req, res) { sendResponse.data = result.request; } - return res.status(404),send(sendResponse); + return res.status(404).send(sendResponse); } @@ -221,4 +221,4 @@ module.exports = { parseRequest: parseRequest, getAuthentication: getAuthentication, combineWithAuthentication: combineWithAuthentication -} \ No newline at end of file +} From c01d6205265d6d1ecee9febf595e8c0ea57a1e95 Mon Sep 17 00:00:00 2001 From: David Welch Date: Tue, 9 May 2017 11:31:43 -0600 Subject: [PATCH 2/3] Support JSON request body parsing --- restly.js | 1 + 1 file changed, 1 insertion(+) diff --git a/restly.js b/restly.js index 4b2f586..9c51e53 100644 --- a/restly.js +++ b/restly.js @@ -19,6 +19,7 @@ var app = express(); // force express to parse posted and putted parameters app.use(bodyParser.urlencoded({ extended: true, uploadDir: '/tmp' })); +app.use(bodyParser.json()); // define public directory for docs app.use(express.static(__dirname+'/public')); From 23f8f278ccd67094b0ce17f3823da9606eafaa90 Mon Sep 17 00:00:00 2001 From: David Welch Date: Tue, 9 May 2017 11:33:00 -0600 Subject: [PATCH 3/3] Pass along a third param to routes Contains req / res --- lib/routes.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/routes.js b/lib/routes.js index 902d28f..3e2f7e2 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -140,6 +140,12 @@ var delegate = function (apicall, opts, req, res) { // load the library var lib = require(apicall.library); + // prepare the context for req / res + var ctx = { + req: req, + res: res + } + // call the callback lib[apicall.callback](opts, function(err, data) { @@ -150,7 +156,7 @@ var delegate = function (apicall, opts, req, res) { return callback(err, data); - }); + }, ctx); }