From d62825e101bbe9b75127733676e9352dcb4156dc Mon Sep 17 00:00:00 2001 From: Olivia Yu Date: Mon, 20 May 2024 09:38:27 -0700 Subject: [PATCH] Set up proxy for business search --- src/components/BusinessCard.js | 4 +--- src/setupProxy.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 src/setupProxy.js diff --git a/src/components/BusinessCard.js b/src/components/BusinessCard.js index 0c5a765..10f9151 100644 --- a/src/components/BusinessCard.js +++ b/src/components/BusinessCard.js @@ -10,9 +10,7 @@ function BusinessCard({ location, onChangeLocation }) { axios .request({ method: 'GET', - // for local development `lcp --proxyUrl https://api.yelp.com/` to avoid CORS issue - // url: 'http://localhost:8010/proxy/v3/businesses/search', - url: 'https://api.yelp.com/v3/businesses/search', + url: '/v3/businesses/search', params: { sort_by: 'best_match', limit: '10', diff --git a/src/setupProxy.js b/src/setupProxy.js new file mode 100644 index 0000000..7485d42 --- /dev/null +++ b/src/setupProxy.js @@ -0,0 +1,11 @@ +const createProxyMiddleware = require('http-proxy-middleware') + +module.exports = function (app) { + app.use( + '/v3/businesses/search', + createProxyMiddleware({ + target: 'https://api.yelp.com', + changeOrigin: true, + }) + ) +}