Skip to content

Commit

Permalink
Merge pull request #71 from rahulpoonia29/ENV-Variables
Browse files Browse the repository at this point in the history
Added support for ENV varialbles
  • Loading branch information
Satyam1923 authored May 13, 2024
2 parents 14c0967 + 6875ff6 commit 4af5e64
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
22 changes: 12 additions & 10 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import express from "express";
import axios from "axios";
import bodyParser from "body-parser";
import cors from "cors";
import cors from "cors";

const cache = new Map();

const app = express();
const port = 3030;
const PORT = 3030;
let name = "";

app.use(bodyParser.urlencoded({ extended: true }));
Expand Down Expand Up @@ -34,11 +34,15 @@ app.get("/search", async (req, res) => {
response.data.data.results.length > 0
) {
const musicArray = response.data.data.results.map((result) => ({
url: result.downloadUrl[4]?.url||'',
name: result.name||'',
year: result.year||'',
artist: result.artists.primary[0]?.name.replace(/&/g, '&') || "",
img: result.image[2]?.url||'',
url: result.downloadUrl[4]?.url || "",
name: result.name || "",
year: result.year || "",
artist:
result.artists.primary[0]?.name.replace(
/&/g,
"&"
) || "",
img: result.image[2]?.url || "",
}));
cache.set(name, musicArray);
res.json(musicArray);
Expand All @@ -54,8 +58,6 @@ app.get("/search", async (req, res) => {
}
});



app.listen(port, () => {
app.listen(PORT, () => {
console.log(`Server is running on port ${port}`);
});
1 change: 1 addition & 0 deletions frontend/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_BACKEND_URL="http://localhost:3030"
2 changes: 2 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ dist-ssr
*.njsproj
*.sln
*.sw?

.env
9 changes: 3 additions & 6 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ const App = () => {

const fetchSongData = async () => {
try {
const response = await axios.get(
"https://spring-music-player-3hyj.vercel.app/search",
{
params: { song: searchQuery },
}
);
const response = await axios.get(import.meta.env.VITE_BACKEND_URL, {
params: { song: searchQuery },
});
setData(response.data);
} catch (error) {
console.error(error);
Expand Down

0 comments on commit 4af5e64

Please sign in to comment.