You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import * as express from "express";
|
|
|
|
import * as cors from "cors";
|
|
|
|
|
|
|
|
import catsRouter from "./cats/cats.route";
|
|
|
|
|
|
|
|
const app: express.Express = express();
|
|
|
|
const port: number = 8000;
|
|
|
|
|
|
|
|
app.use(cors());
|
|
|
|
|
|
|
|
// * Logging Middleware
|
|
|
|
app.use((req, res, next) => {
|
|
|
|
console.log(req.rawHeaders[1]);
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
|
|
|
|
// * json middleware
|
|
|
|
app.use(express.json());
|
|
|
|
|
|
|
|
app.use(catsRouter);
|
|
|
|
|
|
|
|
// * 404 middleware
|
|
|
|
app.use((req, res, next) => {
|
|
|
|
console.log(req.rawHeaders[1]);
|
|
|
|
console.log("This is 404 middleware");
|
|
|
|
res.send({ error: "404 not found error" });
|
|
|
|
});
|
|
|
|
|
|
|
|
app.listen(port, () => {
|
|
|
|
console.log(`server is on ${port}`);
|
|
|
|
});
|