const express = require("express"); const app = express(); const bodyParser = require("body-parser"); const path = require("path"); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); // In-memory database let users = [{ id: 1, name: "Admin", email: "admin@example.com", password: "1234", role: "admin" }]; let posts = [ { id: 1, title: "Copyright Protection Guide", content: "Learn how to protect your content online." }, { id: 2, title: "DMCA Takedown Method", content: "Steps to remove stolen content from websites." } ]; let loggedIn = false; // Serve homepage app.get("/", (req, res) => { let html = ` CopyrightPro CMS

CopyrightPro CMS

Latest Posts

`; posts.forEach(p => { html += `

${p.title}

${p.content}

`; }); html += `
`; res.send(html); }); // Admin login page app.get("/admin", (req, res) => { if (!loggedIn) { res.send(`

Admin Login

`); } else { let postList = posts.map(p => `
  • ${p.title}
  • `).join(""); res.send(`

    Admin Dashboard

    Existing Posts

    `); } }); // Login logic app.post("/login", (req, res) => { const { email, password } = req.body; const user = users.find(u => u.email === email && u.password === password); if (user && user.role === "admin") { loggedIn = true; res.redirect("/admin"); } else { res.send("Invalid credentials. Back"); } }); // Logout app.post("/logout", (req, res) => { loggedIn = false; res.redirect("/admin"); }); // Publish post app.post("/post", (req, res) => { if (!loggedIn) return res.send("Login required."); const { title, content } = req.body; posts.push({ id: Date.now(), title, content }); res.redirect("/admin"); }); app.listen(3000, () => { console.log("Full CMS running at http://localhost:3000"); });