Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { send, json } = require('micro')
- const { router, get, post } = require('microrouter')
- const cors = require('micro-cors')()
- const contacts = [{ "name": "Tyler" }, { "name": "Wes" }, { "name": "David" }]
- const getContacts = async (req, res) => {
- console.log(contacts)
- send(res, 200, contacts)
- }
- const createContact = async (req, res) => {
- const body = await json(req)
- contacts.push(body)
- send(res, 200, body)
- }
- const hello = (req, res) => send(res, 200, `Hello ${req.params.who}`)
- const notfound = (req, res) => send(res, 404, 'Not found route')
- module.exports = cors(
- router(
- get('/contacts', getContacts),
- post('/contacts', createContact),
- get('/hello/:who', hello),
- get('/*', notfound)
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement