// Importing necessary libraries const express = require('express'); const bodyParser = require('body-parser'); const session = require('express-session'); const app = express(); const PORT = process.env.PORT || 3000; // Middleware app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.use(session({ secret: 'your_secret_key', resave: false, saveUninitialized: true, })); // Admin login route app.post('/admin/login', (req, res) => { const { username, password } = req.body; // Replace with your own authentication logic if (username === 'admin' && password === 'password') { req.session.user = { username }; return res.status(200).json({ message: 'Login successful' }); } return res.status(401).json({ message: 'Invalid credentials' }); }); // Admin dashboard route app.get('/admin/dashboard', (req, res) => { if (req.session.user) { return res.status(200).json({ message: 'Welcome to the admin dashboard', user: req.session.user }); } return res.status(403).json({ message: 'Access denied' }); }); // Start the server app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); });