Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for ENV varialbles #71

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=""
rahulpoonia29 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -13,12 +13,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