Skip to content

Commit d43db31

Browse files
committed
Add JSONAPI Content-Type handling
1 parent ac7efea commit d43db31

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

helpers/mu/server.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
import express from 'express';
2+
import bodyParser from 'body-parser';
23

34
var app = express();
45

6+
// parse JSONAPI content type
7+
app.use(bodyParser.json( { type: function(req) { return /^application\/vnd\.api\+json/.test(req.get('content-type')); } } ));
8+
app.use(bodyParser.urlencoded({ extended: false }));
9+
10+
// set JSONAPI content type
11+
app.use('/', function(req, res, next) {
12+
res.type('application/vnd.api+json');
13+
next();
14+
});
15+
16+
// start server
517
app.listen( 80, function() {
618
console.log('Starting server on port 80');
719
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"mu-semtech"
1515
],
1616
"dependencies": {
17+
"body-parser": "~1.15.1",
1718
"express": "^4.14.0"
1819
},
1920
"devDependencies": {

0 commit comments

Comments
 (0)