Added basic proxy example, fixed circular references in helpers/client
Project: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/commit/7d3b487d Tree: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/tree/7d3b487d Diff: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/diff/7d3b487d Branch: refs/heads/master Commit: 7d3b487de39cdd9269e76c3b98a5dd9e5576c5d9 Parents: 987ec65 Author: brandon <[email protected]> Authored: Thu Feb 18 09:57:11 2016 -0800 Committer: brandon <[email protected]> Committed: Thu Feb 18 09:57:11 2016 -0800 ---------------------------------------------------------------------- examples/api-proxy/app.js | 22 ++++++++++++++++++++++ examples/api-proxy/config/usergrid.json | 8 ++++++++ examples/api-proxy/package.json | 19 +++++++++++++++++++ helpers/client.js | 6 +++--- 4 files changed, 52 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/7d3b487d/examples/api-proxy/app.js ---------------------------------------------------------------------- diff --git a/examples/api-proxy/app.js b/examples/api-proxy/app.js new file mode 100644 index 0000000..608f17f --- /dev/null +++ b/examples/api-proxy/app.js @@ -0,0 +1,22 @@ +var express = require('express'), + app = express(), + Usergrid = require('usergrid'), + async = require('async'), + chance = require('chance') + +Usergrid.init() + +app.get('/:collection/:uuidOrName?', function(req, res) { + Usergrid.GET(req.params.collection, req.params.uuidOrName, function(error, usergridResponse, entities) { + res.json(entities); + }) +}) + +app.listen(process.env.port || 9000) + +/* + +1. Start the server using > node app.js +2. Call the api at http://localhost:9000/cats/test + +*/ \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/7d3b487d/examples/api-proxy/config/usergrid.json ---------------------------------------------------------------------- diff --git a/examples/api-proxy/config/usergrid.json b/examples/api-proxy/config/usergrid.json new file mode 100644 index 0000000..5d13860 --- /dev/null +++ b/examples/api-proxy/config/usergrid.json @@ -0,0 +1,8 @@ +{ + "appId": "sandbox", + "orgId": "brandon.apigee", + "authFallback": "NONE", + "baseUrl": "https://api.usergrid.com", + "clientId": "YXA6GXSAACS2EeOYd20aP4G6Lw", + "clientSecret": "YXA66BeEvgNpJBwc4PAbvZZGTVS_SSw" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/7d3b487d/examples/api-proxy/package.json ---------------------------------------------------------------------- diff --git a/examples/api-proxy/package.json b/examples/api-proxy/package.json new file mode 100644 index 0000000..53deec5 --- /dev/null +++ b/examples/api-proxy/package.json @@ -0,0 +1,19 @@ +{ + "dependencies": { + "async": "latest", + "express": "latest", + "usergrid": "r3mus/usergrid-nodejs", + "chance": "^0.8.0" + }, + "description": "A sample API proxy built with Express and Usergrid", + "keywords": [], + "license": "MIT", + "main": "app.js", + "name": "usergrid-example-api-proxy", + "private": false, + "scripts": { + "start": "node app.js", + "test": "mocha tests" + }, + "version": "2.0.0-rc.1" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/7d3b487d/helpers/client.js ---------------------------------------------------------------------- diff --git a/helpers/client.js b/helpers/client.js index e506b88..4d4d311 100644 --- a/helpers/client.js +++ b/helpers/client.js @@ -1,14 +1,13 @@ 'use strict' -var UsergridClient = require('../lib/client'), - UsergridAuth = require('../lib/auth'), - Usergrid = require('../usergrid'), +var Usergrid = require('../usergrid'), helpers = require('../helpers'), _ = require('lodash') module.exports = { validate: function(args) { + var UsergridClient = require('../lib/client') var client if (args instanceof UsergridClient) { client = args @@ -22,6 +21,7 @@ module.exports = { return client }, configureTempAuth: function(auth) { + var UsergridAuth = require('../lib/auth') if (_.isString(auth) && auth !== UsergridAuth.NO_AUTH) { return new UsergridAuth(auth) } else if (!auth || auth === UsergridAuth.NO_AUTH) {
