Skip to content

Commit

Permalink
Update application
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenthphung committed Feb 8, 2024
1 parent 36ed762 commit fdae4bd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
Binary file modified .DS_Store
Binary file not shown.
38 changes: 18 additions & 20 deletions api/search.js
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 modified src/.DS_Store
Binary file not shown.
Binary file modified src/components/.DS_Store
Binary file not shown.
15 changes: 10 additions & 5 deletions vercel.json
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"
}
]
}
}

1 comment on commit fdae4bd

@vercel
Copy link

@vercel vercel bot commented on fdae4bd Feb 8, 2024

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

Please sign in to comment.