summaryrefslogtreecommitdiffstats
path: root/server/server.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/server.js')
-rw-r--r--server/server.js25
1 files changed, 17 insertions, 8 deletions
diff --git a/server/server.js b/server/server.js
index b795846..5f714e4 100644
--- a/server/server.js
+++ b/server/server.js
@@ -1,4 +1,3 @@
-require('dotenv').config(); // Add this line at the top
const express = require('express');
const { exec } = require('child_process');
const path = require('path');
@@ -9,7 +8,7 @@ const bodyParser = require('body-parser');
const app = express();
const port = 5001;
-const adminPassword = process.env.ADMIN_PASSWORD; // Use environment variable
+const adminPassword = process.env.ADMIN_PASSWORD;
app.use(express.json());
app.use(cors());
@@ -114,15 +113,25 @@ const authenticate = (req, res, next) => {
// Endpoint to get influencers
app.get('/influencers', authenticate, (req, res) => {
- const influencers = JSON.parse(fs.readFileSync(path.join(__dirname, 'influencers.json'), 'utf8')).profiles;
- res.json(influencers);
+ 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' });
+ }
});
-// Endpoint to update influencers
+// Endpoint to update influencersData
app.post('/influencers', authenticate, (req, res) => {
- const { profiles } = req.body;
- fs.writeFileSync(path.join(__dirname, 'influencers.json'), JSON.stringify({ profiles }, null, 2));
- res.status(200).json({ message: 'Influencers updated successfully' });
+ 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' });
+ }
});
// Endpoint to export influencers JSON