import * as express from "express"; import * as cors from "cors"; import catsRouter from "./cats/cats.route"; const port: number = 8000; class Server { public app: express.Application; constructor() { const app: express.Application = express(); this.app = app; } private setRoute() { // * router this.app.use(catsRouter); } private setMiddleware() { this.app.use(cors()); // * Logging Middleware this.app.use((req, res, next) => { console.log(req.rawHeaders[1]); next(); }); // * json middleware this.app.use(express.json()); this.setRoute(); // * 404 middleware this.app.use((req, res, next) => { console.log(req.rawHeaders[1]); console.log("This is 404 middleware"); res.send({ error: "404 not found error" }); }); } public listen() { this.setMiddleware(); this.app.listen(port, () => { console.log(`server is on ${port}`); }); } } function init() { const server = new Server(); server.listen(); } init();