| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- const express = require("express");
- const bodyParser = require("body-parser");
- const expressWinston = require("express-winston");
- const winston = require("winston");
- const router = require("./routes");
- const app = express();
- const port = 4000; // set our port
- app.use(bodyParser.urlencoded({ extended: true }));
- app.use(bodyParser.json());
- // Place the express-winston logger before the router.
- app.use(
- expressWinston.logger({
- transports: [new winston.transports.Console()],
- format: winston.format.combine(
- winston.format.colorize(),
- winston.format.simple()
- ),
- meta: true,
- msg: "HTTP {{req.method}} {{req.url}}",
- expressFormat: true,
- colorize: true,
- responseWhitelist: [...expressWinston.requestWhitelist, "body"]
- })
- );
- app.use("/api", router);
- // Place the express-winston errorLogger after the router.
- app.use(
- expressWinston.errorLogger({
- transports: [new winston.transports.Console()],
- format: winston.format.combine(
- winston.format.colorize(),
- winston.format.json()
- )
- })
- );
- app.listen(port);
- /* eslint no-console:0 */
- console.log("Mock is on " + port);
|