diff --git a/index.js b/index.js index 17530dc..a82a339 100644 --- a/index.js +++ b/index.js @@ -5,18 +5,31 @@ const fakedata = require("./prisma/fake-data"); const { PrismaClient } = require("@prisma/client"); const prisma = new PrismaClient(); +// For logging +require("console-stamp")(console); +const elapsed = require("elapsed-time-logger"); + +elapsed.start("init"); + require("dotenv").config(); +console.log("Configuring Express and CORS..."); +elapsed.start("cors"); app.use(express.json()); app.use(cors()); +elapsed.end("cors", "Express and CORS configured in"); // For testing, add intentional delay // app.use(function(req, res, next) { setTimeout(next, 500) }); // Frontend Static +console.log("Adding routes to Express..."); +elapsed.start("static"); const path = __dirname + "/src-frontend-react/build/"; app.use(express.static(path)); +elapsed.end("static", "Static files added in"); +elapsed.start("routes"); const auth = require("./routes/auth.routes.js"); app.use("/backend/auth", auth); @@ -64,7 +77,10 @@ app.post("/backend/fakestaffuser", async (req, res) => { res.status(500).json({ error: "An error occurred!" }); } }); +elapsed.end("routes", "Routed added in"); +console.log("Adding error handling middleware..."); +elapsed.start("errmiddleware"); // Define error handling middleware app.use((err, req, res, next) => { // Handle the error here, for example, send an error response to the client @@ -74,11 +90,17 @@ app.use((err, req, res, next) => { } res.json({ error: "Something went wrong" }); }); +elapsed.end("errmiddleware", "Error middleware added in"); +console.log("Adding catch-all route..."); +elapsed.start("catchall"); // Define a catch-all route at the end of your routes app.all("*", (req, res) => { res.redirect("/"); }); +elapsed.end("catchall", "Catch-all middleware added in"); + +elapsed.end("init", "Server started in"); // function print(path, layer) { // if (layer.route) {