-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36ed762
commit fdae4bd
Showing
5 changed files
with
28 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
const axios = require('axios'); | ||
|
||
module.exports = (req, res) => { | ||
const apiKey = process.env.API_KEY; | ||
module.exports = async (req, res) => { | ||
const apiKey = process.env.API_KEY; // Ensure this is set in your Vercel project settings | ||
const { term, location, sort_by } = req.query; | ||
|
||
console.log('API Key:', apiKey); // add this line | ||
console.log('Request query params:', req.query); // and this line | ||
|
||
axios({ | ||
method: 'get', | ||
url: `https://api.yelp.com/v3/businesses/search?term=${term}&location=${location}&sort_by=${sort_by}`, | ||
headers: { | ||
Authorization: `Bearer ${apiKey}`, | ||
}, | ||
}) | ||
.then((response) => { | ||
console.log('Yelp API response:', response.data); // and this line | ||
res.send(response.data); | ||
}) | ||
.catch((error) => { | ||
console.log('Yelp API error:', error); // and this line | ||
res.status(error.response.status); | ||
res.send(error.response.data); | ||
try { | ||
const { data } = await axios.get(`https://api.yelp.com/v3/businesses/search`, { | ||
params: { term, location, sort_by }, | ||
headers: { | ||
Authorization: `Bearer ${apiKey}`, | ||
}, | ||
}); | ||
res.status(200).json(data); | ||
} catch (error) { | ||
if (error.response) { | ||
// Forward Yelp API's error response | ||
res.status(error.response.status).json(error.response.data); | ||
} else { | ||
// Handle network or other errors | ||
res.status(500).json({ message: 'An error occurred while contacting the Yelp API' }); | ||
} | ||
} | ||
}; |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
{ | ||
"routes": [ | ||
{ | ||
"src": "/(.*)", | ||
"dest": "/index.html" | ||
} | ||
{ | ||
"src": "/api/(.*)", | ||
"dest": "/api/$1" | ||
}, | ||
{ | ||
"src": "/(.*)", | ||
"dest": "/index.html" | ||
} | ||
] | ||
} | ||
} | ||
|
fdae4bd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ravenouseats – ./
ravenouseats-vincentphung.vercel.app
ravenouseats-git-codespace-vincentphung.vercel.app