All files / src app.ts

62.5% Statements 10/16
0% Branches 0/4
0% Functions 0/2
62.5% Lines 10/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 261x 1x   1x   1x   1x 1x   1x   1x       1x               1x  
import createError, { HttpError } from "http-errors";
import express, { Request, Response, NextFunction } from "express";
 
import { postsRouter } from "./routes/postsRouter";
 
const app = express();
 
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
 
app.use("/posts", postsRouter);
 
app.use((_req: Request, _res: Response, next: NextFunction) => {
  next(createError(404));
});
 
app.use((err: HttpError, req: Request, res: Response, _next: NextFunction) => {
  res.locals.message = err.message;
  res.locals.error = req.app.get("env") === "development" ? err : {};
  console.log(err);
  res.status(err.status || 500);
  res.json();
});
 
export { app };