Skip to content

Instantly share code, notes, and snippets.

@mikker
Created January 11, 2017 19:34
Show Gist options
  • Save mikker/1bef412a2072480743facd532fa92b2e to your computer and use it in GitHub Desktop.
Save mikker/1bef412a2072480743facd532fa92b2e to your computer and use it in GitHub Desktop.
/* globals fetch */
require('isomorphic-fetch')
const { parse } = require('url')
const { send } = require('micro')
module.exports = async (req, res) => {
const { query } = parse(req.url)
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Content-Type', 'application/json')
searchItunes(query)
.then(data => { send(res, 200, data) })
.catch(error => { send(res, 500, error) })
}
const searchItunes = (query) =>
fetch(`https://itunes.apple.com/search?${query}`).then(resp => resp.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment