{"_id":"fh-mbaas-express-alpha","_rev":"27-5c48ba6797271918221712fbe0b9838d","name":"fh-mbaas-express-alpha","time":{"modified":"2022-06-18T00:25:11.782Z","created":"2014-05-14T19:30:07.119Z","3.0.0-beta11":"2014-05-14T19:30:13.737Z","3.0.0-beta12":"2014-05-15T15:47:26.957Z","3.0.0-beta13":"2014-05-22T15:55:12.897Z","3.0.0-beta14":"2014-05-30T19:34:51.065Z","3.0.0-beta15":"2014-06-02T14:36:26.868Z"},"maintainers":[{"name":"feedhenry-deprecated","email":"c2131176@trbvn.com"},{"name":"feedhenry-dev","email":"npm@feedhenry.com"},{"name":"grdryn","email":"gryan@redhat.com"}],"dist-tags":{"latest":"3.0.0-beta15"},"description":"FeedHenry MBAAS Express","readme":"fh-mbaas-express\n================\n\nfh-mbaas-express is the FeedHenry MBaaS running on top of [Express](http://expressjs.com/).\n\n# Usage\nAdd the following to the 'dependencies' section of your **'cloud/package.json'** file:\n\n    \"fh-mbaas-express\" : \"~3.0.0\",\n    \"fh-mbaas-api\" : ~3.0.0\"\",\n    \"express\" : \"~4.0.0\"\n\nAdd a file to your FeedHenry app **'cloud/application.js'**, with the following contents:\n\n```javascript\nvar mbaas = require('fh-mbaas-express');\nvar express = require('express');\n\n// Securable endpoints: list the endpoints which you want to make securable here\nvar securableEndpoints = ['hello'];\n\nvar app = express();\n\n// Note: the order which we add middleware to Express here is important!\napp.use('/sys', mbaas.sys(mainjs, securableEndpoints));\napp.use('/mbaas', mbaas.mbaas);\n\n// Note: important that this is added just before your own Routes\napp.use(mbaas.fhmiddleware());\napp.use('/cloud', require('./lib/hello.js')());\n\n\n// You can define custom URL handlers here, like this one:\napp.use('/', function(req, res){\n  res.end('Your Cloud App is Running');\n});\n\n// Important that this is last!\napp.use(mbaas.errorHandler());\n\nvar port = process.env.FH_PORT || process.env.VCAP_APP_PORT || 8001;\nvar server = app.listen(port, function(){\n  console.log(\"App started at: \" + new Date() + \" on port: \" + port);\n});\n```\n\n## Customising & Extending\nThe above application.js is just an [Expressjs application](http://expressjs.com/api.html) - it's easily extensible.\n\n### Custom APIs\nYou can create custom API handlers in the Express format by doing:\n\n    app.use('/myapi', function(req, res){\n      res.end('My custom response');\n    });\n\nSee [Express Router](http://expressjs.com/4x/api.html#router) for more information.\n\n### Serving Static Files\nExpress has a built-in static file server. In this example, we host files under the public directory:  \n    \n    app.use(express.static(__dirname + '/public'));\n\n\n# REST API\t\n\n\n## Cloud\n\n###(POST | GET | PUT) /cloud/:someFunction\n**Authentication** : Optional - can be enabled globally or on a per-endpoint basis under \"Endpoints\" section of the studio.\n**Response formats** : JSON, binary, plain text\n\n###Headers\n**x-fh-auth-app** : API key of your application, found under the \"details\" section of the studio.\n\n###Body:\nJSON format - paramaters to be passed to the exported function, see 'Writing API Functions'.\n###Response:\nResult as passed to the callback function of the exported function - see 'Writing API Functions'.\n\n\n###Writing API functions\n\nWe recommend adding your own routes to `/cloud`, see `lib/hello.js` in the `hello world` example. . Also see [Express Router](http://expressjs.com/4x/api.html#router) for more information.\n\n```javascript\nfunction helloRoute() {\n  var hello = new express.Router();\n  hello.use(bodyParser());\n\n  // GET REST endpoint - query params may or may not be populated\n  hello.get('/hello', function(req, res) {\n    var world = req.query ? req.query.hello : 'World';\n\n    res.writeHead(200, {\"Content-Type\":\"application/json\"});\n    res.end(JSON.stringify({msg: 'Hello ' + world}));\n  });\n  return hello;\n}\n\n```\n\n\n##mBaaS\n###POST /mbaas/db\n**Authentication** : Required - App API key goes here.\n**Response format** : JSON\n\n###Headers\n**x-fh-auth-app** : API key of your application, found under the \"details\" section of the studio.\n\n###POST Body:\nJSON body - same as $fh.db params. A summary of body options follows - For more, see [$fh.db docs](http://docs.feedhenry.com/v2/api_cloud_apis.html#$fh.db)\n\n    {\n        \"act\": \"create|update|list|delete|deleteall\",\n        \"type\": \"collectionName\",\n        \"guid\": \"GUID of object operating on - not required for list or deleteall\",\n        \"fields\": \"JSON definition of fields - required for create|update\",\n        \"eq|ne|in\" : \"JSON definition of query to match - supported for list only\"\n    }\n\n###Response:\nAs per [$fh.db](http://docs.feedhenry.com/v2/api_cloud_apis.html#$fh.db)\n\n##Sys\n##GET /sys/info/ping\n**Authentication** : None\n**Response formats** : Plaintext\n\n###Headers\nNone\n\n###Response:\n    \"OK\"\nif application is running as expected. Will respond with a 404 otherwise\n\n##GET /sys/info/endpoints\n**Authentication** : None\n**Response formats** : JSON\n\n###Headers\nNone\n\n###Response:\n    {\n      endpoints : ['array of endpoints exported as public functions']\n    }\n\n##GET /sys/info/memory\n**Authentication** : None\n**Response formats** : JSON\n\n###Headers\nNone\n\n###Response:\n    {\n      rss: 13721600, // Resident set size\n      heapTotal: 7195904, // V8's total available memory\n      heapUsed: 2369744  // V8's used memory\n    }\n\n##GET /sys/info/memory\n**Authentication** : None\n**Response formats** : Plaintext\n\n###Headers\nNone\n\n###Response:\n    0.1.0\n\n# Backward compatability with main.js\n\nIf you want to use the older fh-nodeapp/fh-webapp style main.js, you need to change the /cloud endpoint in your application.js as follows:\n\n```\nvar mainjs = require('./lib/main.js');\napp.use('/cloud', mbaas.cloud(mainjs));\n```\n\nAdditionally, you need to ammend the call to `sys` for secure endpoints:\n\n```\napp.use('/sys', mbaas.sys(securableEndpoints, mainjs));\n```\n","versions":{"3.0.0-beta12":{"name":"fh-mbaas-express-alpha","version":"3.0.0-beta12","description":"FeedHenry MBAAS Express","main":"lib/webapp.js","author":{"name":"FeedHenry"},"dependencies":{"underscore":"1.5.1","request":"2.25.0","async":"0.2.9","cors":"2.1.0","fh-amqp-js":"0.2.1","fh-reportingclient":"0.2.2","fh-mbaas-api-alpha":"3.0.x","express":"~4.0.0","body-parser":"~1.0.2","type-is":"~1.1.0","multer":"0.0.5"},"directories":{"lib":"lib"},"engines":{"node":">=0.8"},"devDependencies":{"proxyquire":"0.4.1","cli-color":"0.2.2","nock":"0.22.1","turbo-test-runner":"~0.3","istanbul":"0.1.42","form-data":"0.1.2"},"_id":"fh-mbaas-express-alpha@3.0.0-beta12","dist":{"shasum":"15e3a7cb95e77f80c92bcc8f1827a0a72a609955","tarball":"https://registry.npmjs.org/fh-mbaas-express-alpha/-/fh-mbaas-express-alpha-3.0.0-beta12.tgz","integrity":"sha512-UPkE2DjUVRkJlYSPyMmkHoR/T6LiLNj+xoJbeMRw7KlbywbC1yw150lcDERn6Kfct5Ivz+KMJ4fDc/wKJsYucQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCyXuklReHL5+YXLQJFXV8GkZbmusQQ+OfL7mp/7ZymFwIhAP0Nie/P3cB8eI+KwjcbmRiGAo0LRE8ee1J/Egu9ObJI"}]},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"feedhenry","email":"npm@feedhenry.com"},"maintainers":[{"name":"feedhenry","email":"npm@feedhenry.com"}]},"3.0.0-beta13":{"name":"fh-mbaas-express-alpha","version":"3.0.0-beta13","description":"FeedHenry MBAAS Express","main":"lib/webapp.js","author":{"name":"FeedHenry"},"dependencies":{"underscore":"1.5.1","request":"2.25.0","async":"0.2.9","cors":"2.1.0","fh-amqp-js":"0.2.1","fh-reportingclient":"0.2.2","fh-mbaas-api-alpha":"*","express":"~4.0.0","body-parser":"~1.0.2","type-is":"~1.1.0","multer":"0.0.5"},"directories":{"lib":"lib"},"engines":{"node":">=0.8"},"devDependencies":{"proxyquire":"0.4.1","cli-color":"0.2.2","nock":"0.22.1","turbo-test-runner":"~0.3","istanbul":"0.1.42","form-data":"0.1.2"},"_id":"fh-mbaas-express-alpha@3.0.0-beta13","dist":{"shasum":"b39f8b10852b52f90d1e18de641787d61d69075e","tarball":"https://registry.npmjs.org/fh-mbaas-express-alpha/-/fh-mbaas-express-alpha-3.0.0-beta13.tgz","integrity":"sha512-VBR4LzkFJ1IRevTDYG1NCSunqLMffvludlpbXbj9PNsV4SGS9WG6DnxT7AdUNITeW0aEBx9I7F3xBo2Ccz0zCg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCXTzXaR/IeiOqiDuDq4UnQmQiHJdJ2kH0T1MErWgml7QIgSV8IfmUy/jGkIq2iWGd/rdT6NtnYfO8O4zCnYXa/rtM="}]},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"feedhenry","email":"npm@feedhenry.com"},"maintainers":[{"name":"feedhenry","email":"npm@feedhenry.com"}]},"3.0.0-beta14":{"name":"fh-mbaas-express-alpha","version":"3.0.0-beta14","description":"FeedHenry MBAAS Express","main":"lib/webapp.js","author":{"name":"FeedHenry"},"dependencies":{"underscore":"1.5.1","request":"2.25.0","async":"0.2.9","cors":"2.1.0","fh-amqp-js":"0.2.1","fh-reportingclient":"0.2.2","fh-mbaas-api-alpha":"*","express":"~4.0.0","body-parser":"~1.0.2","type-is":"~1.1.0","multer":"0.0.5"},"directories":{"lib":"lib"},"engines":{"node":">=0.8"},"devDependencies":{"proxyquire":"0.4.1","cli-color":"0.2.2","nock":"0.22.1","turbo-test-runner":"~0.3","istanbul":"0.1.42","form-data":"0.1.2"},"_id":"fh-mbaas-express-alpha@3.0.0-beta14","dist":{"shasum":"8ee72e3d6c85d84c84197a1b9221c8de1195caf9","tarball":"https://registry.npmjs.org/fh-mbaas-express-alpha/-/fh-mbaas-express-alpha-3.0.0-beta14.tgz","integrity":"sha512-qhXEovWE5sIsSKc4/S9EreGPeBZCs4CsiV4gyEkZVQmLnleYeyR9eDTaG/CFZNjfI30OAl2cCL4LkkCB8kbCOg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCyO8GJze4HmSALHLU1VDg30KIo3L9ivNlFs/BNAB7DNgIgWVnJrXVCVuXKsl66AcxG94GbEbjYeozah38Cp5MaIOc="}]},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"feedhenry","email":"npm@feedhenry.com"},"maintainers":[{"name":"feedhenry","email":"npm@feedhenry.com"}]},"3.0.0-beta15":{"name":"fh-mbaas-express-alpha","version":"3.0.0-beta15","description":"FeedHenry MBAAS Express","main":"lib/webapp.js","author":{"name":"FeedHenry"},"dependencies":{"underscore":"1.5.1","request":"2.25.0","async":"0.2.9","cors":"2.1.0","fh-amqp-js":"0.2.1","fh-reportingclient":"0.2.2","fh-mbaas-api-alpha":"*","express":"~4.0.0","body-parser":"~1.0.2","type-is":"~1.1.0","multer":"0.0.5"},"directories":{"lib":"lib"},"engines":{"node":">=0.8"},"devDependencies":{"proxyquire":"0.4.1","cli-color":"0.2.2","nock":"0.22.1","turbo-test-runner":"~0.3","istanbul":"0.1.42","form-data":"0.1.2"},"_id":"fh-mbaas-express-alpha@3.0.0-beta15","dist":{"shasum":"235076072151edc78fc3389125aa86a467776ecd","tarball":"https://registry.npmjs.org/fh-mbaas-express-alpha/-/fh-mbaas-express-alpha-3.0.0-beta15.tgz","integrity":"sha512-vWQM7tibCB19eZ+ZoRFKT7WhrvrXycx3wLqAHin6E5yid+RsBqaj41LiVbW0ZVehH6NPtRHgGwo7vYDqX/8IHg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBkPDq59vvEyIPPuZ1DKVbXr5DP8RTwK665U5UrH/NQxAiBBfKWauSET/mS6rXp9VKWyNmSKFudTH1wEi3uxigSZFQ=="}]},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"feedhenry","email":"npm@feedhenry.com"},"maintainers":[{"name":"feedhenry","email":"npm@feedhenry.com"}]}},"author":{"name":"FeedHenry"},"readmeFilename":"README.md"}