Skip to content

Commit

Permalink
Merge pull request #13 from ph0bos/entitlements-functionality
Browse files Browse the repository at this point in the history
Implement entitlements controller
  • Loading branch information
ph0bos committed Nov 8, 2015
2 parents 9cda29f + f028999 commit 082f1da
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ default:

```

In the above example the application would be accessible at the following address: `http://0.0.0.0:8000/starter/v1`, with the `/actuator/info` and `/actuator/health` diagmostic endpoints activated.
In the above example the application would be accessible at the following address: `http://0.0.0.0:8000/starter/v1`, with the `/actuator/info` and `/actuator/health` diagnostic endpoints activated.

## API

Expand All @@ -89,4 +89,4 @@ app.use(micro([options]));
- `discoverable`: `boolean` Register the service with Zookeeper to allow for discovery by other services connecting to the same instance of Zookeeper.
- `controllersPath`: `String` Path to load controllers. Defaults to `controllers`.
- `monitorsPath`: `String` Path to load monitors. Defaults to `monitors`.
- 'partialResponseQuery': `String` The query parameter to use for partial reponse. Defaults to `fields`.
- `partialResponseQuery`: `String` The query parameter to use for partial reponse. Defaults to `fields`.
25 changes: 25 additions & 0 deletions controllers/entitlements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

/*
* Dependencies
*/
var optional = require('optional');
var entitlements = optional(process.cwd() + '/config/entitlements.json');

/**
* Initialize Entitlements endpoints
*
* @param app
*/
module.exports = function (router) {

/*
* Entitlements Endpoint
*/
router.get('/', function (req, res, next) {
if (!entitlements) return res.status(501).send();

res.cacheControl({ maxAge: 3600 });
res.json(entitlements);
});
};
62 changes: 62 additions & 0 deletions example/config/entitlements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"schema": "http://json-schema.org/draft-04/schema#",
"id": "/",
"type": "object",
"properties": {
"embargo": {
"id": "embargo",
"type": "boolean"
},
"competition": {
"id": "competition",
"type": "array",
"items": {
"id": "0",
"type": "object",
"properties": {
"id": {
"id": "id",
"type": "string",
"enum": [
"123"
]
},
"name": {
"id": "name",
"type": "string",
"enum": [
"Sports"
]
}
},
"additionalProperties": false
}
},
"channels": {
"id": "channels",
"type": "array",
"items": {
"id": "0",
"type": "object",
"properties": {
"id": {
"id": "id",
"type": "string",
"enum": [
"12344"
]
},
"name": {
"id": "name",
"type": "string",
"enum": [
"Test"
]
}
},
"additionalProperties": false
}
}
},
"additionalProperties": false
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-microservice-starter",
"version": "0.5.8",
"version": "0.5.9",
"description": "An express-based Node.js API bootstrapping module for microservices.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -36,6 +36,7 @@
"express-partial-response": "^0.3.4",
"ip": "^0.3.2",
"konfig": "^0.2.1",
"optional": "^0.1.3",
"vitalsigns": "^0.4.3",
"zoologist": "^0.4.5"
}
Expand Down

0 comments on commit 082f1da

Please sign in to comment.