File tree Expand file tree Collapse file tree 2 files changed +27
-8
lines changed Expand file tree Collapse file tree 2 files changed +27
-8
lines changed Original file line number Diff line number Diff line change 11'use strict' ;
2-
3- var bodyParser = require ( 'body-parser' ) ;
2+ var is = require ( 'type-is' ) ;
43
54module . exports = function ( app , options ) {
65
7- //registered at the beginning of the routes phase due to usage of
8- //express app.use instead of app.middleware.
9- //We need to do this as bodyParser doesn't support
10- //JSON APIs application/vnd.api+json format by default
11- app . use ( bodyParser . json ( { type : 'application/vnd.api+json' } ) ) ;
6+ app . remotes ( ) . before ( '**' , function ( ctx , next ) {
7+ if ( ctx . req . accepts ( 'application/vnd.api+json' ) ) {
8+ ctx . req . headers . accept = 'application/json' ;
9+ }
10+ next ( ) ;
11+ } ) ;
12+
13+ app . remotes ( ) . options . rest = {
14+ //turn off strong remotings error handler so we can handle ourselves in error.js
15+ handleErrors : false ,
16+
17+ //extend support for application/vnd.api+json
18+ supportedTypes : [ 'json' , 'application/javascript' , 'text/javascript' , 'application/vnd.api+json' ]
19+ } ;
20+
21+ //extend rest body parser to also parse application/vnd.api+json
22+ app . remotes ( ) . options . json = {
23+ strict : false ,
24+ type : function ( req ) {
25+ //if Content-Type is any of the following, then parse otherwise don't
26+ return ! ! is ( req , [ 'json' , 'application/json' , 'application/vnd.api+json' ] ) ;
27+ }
28+ } ;
1229} ;
Original file line number Diff line number Diff line change 2828 "body-parser" : " ^1.14.1" ,
2929 "debug" : " ^2.2.0" ,
3030 "inflection" : " ^1.7.2" ,
31- "lodash" : " ^3.10.1"
31+ "lodash" : " ^3.10.1" ,
32+ "loopback" : " ^2.22.2" ,
33+ "type-is" : " ^1.6.9"
3234 },
3335 "devDependencies" : {
3436 "babel-eslint" : " ^4.1.3" ,
You can’t perform that action at this time.
0 commit comments