diff options
author | Biswakalyan Bhuyan <biswa@surgot.in> | 2024-06-28 18:00:44 +0530 |
---|---|---|
committer | Biswakalyan Bhuyan <biswa@surgot.in> | 2024-06-28 18:00:44 +0530 |
commit | 251ff2f06d8e118e3e81b0458d284fbf62af1934 (patch) | |
tree | 6196cb60fb134dc631446516a5ee0b367b21f370 /server | |
parent | 8329db0b28cf1a65350daf5505f375cc000383e7 (diff) | |
download | insta-local-251ff2f06d8e118e3e81b0458d284fbf62af1934.tar.gz insta-local-251ff2f06d8e118e3e81b0458d284fbf62af1934.tar.bz2 insta-local-251ff2f06d8e118e3e81b0458d284fbf62af1934.zip |
adding the influencer page and adding the funcitons in it
Diffstat (limited to 'server')
-rw-r--r-- | server/server.js | 25 |
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 |