|
1 | | -var url = require('url'); |
2 | | -var utils = require('./utils'); |
3 | | -var statusCodes = require('http-status-codes'); |
| 1 | +var url = require('url') |
| 2 | +var utils = require('./utils') |
| 3 | +var statusCodes = require('http-status-codes') |
4 | 4 |
|
5 | 5 | module.exports = function (app, options) { |
6 | | - //get remote methods. |
7 | | - //set strong-remoting for more information |
8 | | - //https://github.com/strongloop/strong-remoting |
9 | | - var remotes = app.remotes(); |
| 6 | + // get remote methods. |
| 7 | + // set strong-remoting for more information |
| 8 | + // https://github.com/strongloop/strong-remoting |
| 9 | + var remotes = app.remotes() |
10 | 10 |
|
11 | | - //register after remote method hook on all methods |
| 11 | + // register after remote method hook on all methods |
12 | 12 | remotes.after('**', function (ctx, next) { |
13 | | - |
14 | 13 | if (utils.shouldNotApplyJsonApi(ctx, options)) { |
15 | | - return next(); |
16 | | - }; |
| 14 | + return next() |
| 15 | + } |
17 | 16 |
|
18 | | - //in this case we are only interested in handling create operations. |
| 17 | + // in this case we are only interested in handling create operations. |
19 | 18 | if (ctx.method.name === 'create') { |
20 | | - //JSON API specifies that created resources should have the |
21 | | - //http status code of 201 |
22 | | - ctx.res.statusCode = statusCodes.CREATED; |
| 19 | + // JSON API specifies that created resources should have the |
| 20 | + // http status code of 201 |
| 21 | + ctx.res.statusCode = statusCodes.CREATED |
23 | 22 |
|
24 | | - //build the location url for the created resource. |
| 23 | + // build the location url for the created resource. |
25 | 24 | var location = url.format({ |
26 | 25 | protocol: ctx.req.protocol, |
27 | 26 | host: ctx.req.get('host'), |
28 | 27 | pathname: ctx.req.baseUrl + '/' + ctx.result.data.id |
29 | | - }); |
| 28 | + }) |
30 | 29 |
|
31 | | - //we don't need the links property so just delete it. |
32 | | - delete ctx.result.links; |
| 30 | + // we don't need the links property so just delete it. |
| 31 | + delete ctx.result.links |
33 | 32 |
|
34 | | - //JSON API specifies that when creating a resource, there should be a |
35 | | - //location header set with the url of the created resource as the value |
36 | | - ctx.res.append('Location', location); |
| 33 | + // JSON API specifies that when creating a resource, there should be a |
| 34 | + // location header set with the url of the created resource as the value |
| 35 | + ctx.res.append('Location', location) |
37 | 36 | } |
38 | | - next(); |
39 | | - }); |
40 | | -}; |
| 37 | + next() |
| 38 | + }) |
| 39 | +} |
0 commit comments