Skip to content

Admin Area Preparation

Before we start wiring up delete buttons and modifying documents, we need a dedicated space for these operations. We don’t want our mutation logic scattered randomly across the application.

By creating a dedicated Admin Router, we establish a clean, predictable convention. All administrative actions (like viewing raw submissions, editing projects, or deleting data) will live under the /admin/* path.

Think of the adminRouter.js as the secure wing of our application. Later on, this is where we will drop an authentication gate (middleware) so that only authorized users can cross the threshold. For now, it simply keeps our code organized.

routers/adminRouter.js
const express = require("express");
const router = express.Router();
const _contactOps = require("../data/contacts");
// Admin: contacts inbox page
router.get("/contacts", async (req, res) => {
const contacts = await _contactOps.getAllContactsAdmin();
res.render("admin-contacts", { contacts });
});
// Future mutation routes (delete/update) will go here!
module.exports = router;
Professor Solo

By isolating these routes early, we foreshadow authentication. When the time comes to secure the app, we only have to lock one door (the /admin prefix) instead of fifty individual routes.


Now that we have a secure route, let’s build the view to see what we’re working with.