b5e3aac1ec
* Fix POST and PUT * Fix condition for request and test
14 lines
364 B
JavaScript
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)
|
|
}
|
|
}
|