Skip to content

Commit 66e4ee7

Browse files
committed
add json support
1 parent c2b55c8 commit 66e4ee7

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

api.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
import { json } from 'body-parser'
2+
13
export default [
24
{
35
path: '/api/ping',
46
handler(req, res, next) {
57
res.end(`API pong at ${new Date().getTime()}`)
68
}
9+
},
10+
json(),
11+
(req, res, next) => {
12+
res.json = (obj) => res.write(JSON.stringify(obj))
13+
next()
714
}
815
]

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"nuxt": "^2.6.3"
1919
},
2020
"dependencies": {
21-
"@nuxt/http": "^0.1.1"
21+
"@nuxt/http": "^0.1.1",
22+
"body-parser": "^1.19.0"
2223
}
2324
}

0 commit comments

Comments
 (0)