diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/server.js | 25 |
1 files changed, 8 insertions, 17 deletions
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 |