From ac0257db671bce0ae2ba160ba93018317184256a Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Fri, 28 Jun 2024 20:57:46 +0530 Subject: Revert "adding the influencer page and adding the funcitons in it" This reverts commit 4a580e70d713ee80a0093663b665402e1bef5fc9. --- server/server.js | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'server') diff --git a/server/server.js b/server/server.js index 5f714e4..b795846 100644 --- a/server/server.js +++ b/server/server.js @@ -1,3 +1,4 @@ +require('dotenv').config(); // Add this line at the top const express = require('express'); const { exec } = require('child_process'); const path = require('path'); @@ -8,7 +9,7 @@ const bodyParser = require('body-parser'); const app = express(); const port = 5001; -const adminPassword = process.env.ADMIN_PASSWORD; +const adminPassword = process.env.ADMIN_PASSWORD; // Use environment variable app.use(express.json()); app.use(cors()); @@ -113,25 +114,15 @@ const authenticate = (req, res, next) => { // Endpoint to get influencers app.get('/influencers', authenticate, (req, res) => { - try { - const influencersData = JSON.parse(fs.readFileSync(path.join(__dirname, 'influencers.json'), 'utf8')); - res.json(influencersData.profiles); - } catch (error) { - console.error('Error fetching influencers:', error); - res.status(500).json({ error: 'Error fetching influencers' }); - } + const influencers = JSON.parse(fs.readFileSync(path.join(__dirname, 'influencers.json'), 'utf8')).profiles; + res.json(influencers); }); -// Endpoint to update influencersData +// Endpoint to update influencers app.post('/influencers', authenticate, (req, res) => { - try { - const { profiles } = req.body; - const influencersData = { profiles }; - fs.writeFileSync(path.join(__dirname, 'influencers.json'), JSON.stringify(updatedData, null, 2)); - } catch (error) { - console.error('Error updating influencers:', error); - res.status(500).json({ error: 'Error updating influencers' }); - } + const { profiles } = req.body; + fs.writeFileSync(path.join(__dirname, 'influencers.json'), JSON.stringify({ profiles }, null, 2)); + res.status(200).json({ message: 'Influencers updated successfully' }); }); // Endpoint to export influencers JSON -- cgit v1.2.3-59-g8ed1b