rsnext/test/integration/api-support/pages/api/posts/index.js
Lukáš Huvar b5e3aac1ec Fix POST and PUT on api routes (#7319)
* Fix POST and PUT

* Fix condition for request and test
2019-05-13 15:40:23 +02:00

14 lines
364 B
JavaScript

import url from 'url'
export default (req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' })
if (req.method === 'POST') {
const { query } = url.parse(req.url, true)
const json = JSON.stringify([{ title: query.title }])
res.end(json)
} else {
const json = JSON.stringify([{ title: 'Cool Post!' }])
res.end(json)
}
}