From f81ceb9e3f9c8d25b24dfea45d2e67f522a65b6c Mon Sep 17 00:00:00 2001 From: Jared Galanis Date: Wed, 17 Apr 2019 09:45:28 -0600 Subject: [PATCH 1/2] Move repo query to server --- app/routes/index.js | 5 ++--- server/proxies/api-proxy.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/routes/index.js b/app/routes/index.js index 68c98b3..990aebb 100644 --- a/app/routes/index.js +++ b/app/routes/index.js @@ -3,10 +3,9 @@ import Route from '@ember/routing/route'; export default Route.extend({ model() { - fetch('https://api.github.com/search/repositories?q=user:ember-learn+NOT+builds+NOT+statusboard+help-wanted-issues:%3E0+archived:false') + fetch('/github-repositories') .then((response) => response.json()) - .then((repos) => this.store.pushPayload('github-repository', { githubRepository: repos.items })); + .then((repos) => this.store.pushPayload('github-repository', { githubRepository: repos })); return this.store.peekAll('github-repository'); } - }); diff --git a/server/proxies/api-proxy.js b/server/proxies/api-proxy.js index 9b1ab15..8db8a0d 100644 --- a/server/proxies/api-proxy.js +++ b/server/proxies/api-proxy.js @@ -2,7 +2,8 @@ 'use strict'; const httpProxy = require('http-proxy'); -const proxyPath = '/github-issues'; +const issuesProxyPath = '/github-issues'; +const reposProxyPath = '/github-repositories'; let target; if (process.env.LOCAL_API) { @@ -29,8 +30,12 @@ module.exports = function(app) { console.error(err, req.url); }); - app.use(proxyPath, function(req, res) { - req.url = `${proxyPath}/${req.url}`; + app.use(issuesProxyPath, function(req, res) { + req.url = `${issuesProxyPath}/${req.url}`; + proxy.web(req, res, { target }); + }); + app.use(reposProxyPath, function(req, res) { + req.url = `${reposProxyPath}/${req.url}`; proxy.web(req, res, { target }); }); }; From 483a2c344de805e8e7c7ff8a9b04a87b7465c4a3 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Thu, 18 Apr 2019 08:13:11 +0100 Subject: [PATCH 2/2] adding API_HOST to the fetch call for repos --- app/routes/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/routes/index.js b/app/routes/index.js index 990aebb..d8cefbd 100644 --- a/app/routes/index.js +++ b/app/routes/index.js @@ -1,9 +1,12 @@ import Route from '@ember/routing/route'; +import ENV from 'ember-help-wanted/config/environment'; export default Route.extend({ model() { - fetch('/github-repositories') + let host = ENV.API_HOST || ''; + + fetch(`${host}/github-repositories`) .then((response) => response.json()) .then((repos) => this.store.pushPayload('github-repository', { githubRepository: repos })); return this.store.peekAll('github-repository');