Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MONGODB_URI=mongodb+srv://Astrav:sempala152@beatwave.rr74j.mongodb.net/beatwave?retryWrites=true&w=majority&appName=beatwave
REACT_APP_API_URL=https://beatwave-api.onrender.com
REACT_APP_API_URL=https://beat-wave.onrender.com
9 changes: 7 additions & 2 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[build]
publish = "/"
command = "# no build command needed"
publish = "public"
command = "npm install"

[[redirects]]
from = "/api/*"
to = "https://beat-wave.onrender.com/api/:splat"
status = 200

[[redirects]]
from = "/*"
Expand Down
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "beatwave",
"version": "1.0.0",
"description": "Music streaming application",
"main": "server.js",
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
},
"dependencies": {
"express": "^4.18.2",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"mongoose": "^7.6.3",
"ytdl-core": "^4.11.5",
"axios": "^1.6.2",
"ws": "^8.16.0",
"spotify-web-api-node": "^5.0.2"
},
"devDependencies": {
"nodemon": "^3.0.2"
},
"engines": {
"node": "18.x"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions auth.js → public/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Mock Database (You can replace this with real backend integration later)
const users = [];
// auth.js
const API_URL = 'https://beat-wave.onrender.com';

// Handle Sign-Up
async function handleSignUp(event) {
Expand All @@ -17,7 +19,7 @@ async function handleSignUp(event) {
};

try {
const response = await fetch('http://localhost:5000/api/users/register', {
const response = await fetch('${process.env.REACT_APP_API_URL}users/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand Down Expand Up @@ -54,7 +56,7 @@ async function handleLogin(event) {
};

try {
const response = await fetch('http://localhost:5000/api/users/login', {
const response = await fetch('${process.env.REACT_APP_API_URL}users/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions homepage.js → public/homepage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
let isLoggedIn = false; // Track login state
const API_URL = 'https://beat-wave.onrender.com';

// Utility Functions
const utils = {
Expand Down Expand Up @@ -129,7 +130,7 @@ const musicDownloader = {
}
});

const downloadUrl = `http://localhost:5000/api/songs/download?videoUrl=${encodeURIComponent(videoUrl)}`;
const downloadUrl = `${process.env.REACT_APP_API_URL}songs/download?videoUrl=${encodeURIComponent(videoUrl)}`;

// Use fetch with timeout
const response = await fetch(downloadUrl, {
Expand Down Expand Up @@ -164,7 +165,7 @@ const musicDownloader = {
// Fetch and render latest music
async function fetchAndRenderLatestMusic() {
try {
const response = await fetch('http://localhost:5000/api/songs/latest');
const response = await fetch('${process.env.REACT_APP_API_URL}songs/latest');
const data = await response.json();

if (response.ok) {
Expand All @@ -181,7 +182,7 @@ async function fetchAndRenderLatestMusic() {
// Fetch and render trending music
async function fetchAndRenderTrendingMusic() {
try {
const response = await fetch('http://localhost:5000/api/songs/trending');
const response = await fetch('${process.env.REACT_APP_API_URL}songs/trending');
const data = await response.json();

if (response.ok) {
Expand Down Expand Up @@ -304,7 +305,7 @@ document.addEventListener('DOMContentLoaded', () => {
const searchHandler = {
async searchSongs(query) {
try {
const response = await fetch(`http://localhost:5000/api/songs/search?query=${encodeURIComponent(query)}`);
const response = await fetch(`${process.env.REACT_APP_API_URL}songs/search?query=${encodeURIComponent(query)}`);
const data = await response.json();

if (response.ok) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
61 changes: 36 additions & 25 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
// server.js
const mongoose = require('mongoose');
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
require('dotenv').config(); // For environment variables
const mongoose = require('mongoose');
const WebSocket = require('ws');
const http = require('http');
require('dotenv').config();

const app = express();
app.use(cors());
app.use(bodyParser.json()); // For parsing application/json

// MongoDB Atlas connection URI
const uri = process.env.MONGODB_URI; // Store your connection string in .env

// Connect to MongoDB with increased timeout settings
mongoose.connect(uri, {
serverSelectionTimeoutMS: 30000, // Increase timeout to 30 seconds
socketTimeoutMS: 45000 // Increase socket timeout to 45 seconds
}).then(() => {
console.log("Connected to MongoDB!");
}).catch(err => {
console.error("Error connecting to MongoDB:", err);
const server = http.createServer(app);
const wss = new WebSocket.Server({ server });

app.use(cors({
origin: ['https://beatwave13.netlify.app', 'http://localhost:3000'],
credentials: true
}));

app.use(express.json());

// WebSocket connection handling
wss.on('connection', (ws) => {
ws.id = Math.random().toString(36).substr(2, 9);
console.log('New client connected');

ws.on('close', () => {
console.log('Client disconnected');
});
});

// Import routes
const songRoutes = require('./api/routes/songRoutes'); // Ensure the correct path
// Add WebSocket server to app
app.set('wss', wss);

// Routes
app.use('/api/songs', require('./api/routes/songRoutes'));
app.use('/api/users', require('./api/routes/userRoutes'));

// Use routes
app.use('/api/songs', songRoutes);
const PORT = process.env.PORT || 10000;

const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
mongoose.connect(process.env.MONGODB_URI)
.then(() => {
server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
})
.catch(err => console.error('MongoDB connection error:', err));