All files / src app.js

100% Statements 19/19
100% Branches 2/2
100% Functions 2/2
100% Lines 19/19

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 26 27 28 29 30 31 32 33 344x 4x 4x 4x 4x 4x 4x 4x   4x   4x   210x       4x     4x   4x     4x   4x 1x     4x   4x
const path = require("path");
const express = require('express');
const questionsRouter = require ("./routes/questions");
const authRouter = require("./routes/auth");
const errorHandler = require("./middleware/errorHandler");
const { NotFoundError } = require("./lib/errors");
const pinoHttp = require("pino-http");
const logger = require("./lib/logger");
 
const app = express();
 
app.use(pinoHttp({logger,
  autoLogging: {ignore: req => 
    req.url.startsWith("/uploads") || req.url.startsWith("/static"),
  },
}));
 
app.use(express.static(path.join(__dirname, '..', 'public')));
 
// Middleware to parse JSON bodies (will be useful in later steps)
app.use(express.json());
 
app.use("/api/auth", authRouter);
 
// everything under /api/questions
app.use("/api/questions", questionsRouter);
 
app.use((req, res) => {
  throw new NotFoundError();
});
 
app.use(errorHandler);
 
module.exports = app;