From b5cb3e78abf253d8fa3b5aefc1e9dc463ab50e67 Mon Sep 17 00:00:00 2001 From: Jonathan Cremin Date: Sun, 23 Oct 2016 21:48:44 +0100 Subject: [PATCH] Add itunes proxy back :( --- app.js | 2 ++ routes/itunes-proxy.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 routes/itunes-proxy.js diff --git a/app.js b/app.js index b7ab276..461218e 100644 --- a/app.js +++ b/app.js @@ -14,6 +14,7 @@ import index from './routes/index'; import recent from './routes/recent'; import search from './routes/search'; import share from './routes/share'; +import itunesProxy from './routes/itunes-proxy'; const debug = debuglog('match.audio'); @@ -38,6 +39,7 @@ app.use(route.get('/', index)); app.use(route.get('/recent', recent)); app.use(route.post('/search', search)); app.use(route.get('/:service/:type/:id.:format?', share)); +app.use(route.get('/itunes/(.*)', itunesProxy)); if (!module.parent) { app.listen(process.env.PORT || 3000, () => { diff --git a/routes/itunes-proxy.js b/routes/itunes-proxy.js new file mode 100644 index 0000000..11dc5bd --- /dev/null +++ b/routes/itunes-proxy.js @@ -0,0 +1,14 @@ +import { parse } from 'url'; +import request from 'superagent'; + +export default function* (next) { + const url = `http://${this.request.url.substr(8)}`; + const parsed = parse(url); + if (parsed.host.match(/mzstatic\.com/)) { + const proxyResponse = yield request.get(url); + this.set(proxyResponse.headers); + this.body = proxyResponse.body; + } else { + yield next; + } +}