-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (53 loc) · 1.72 KB
/
app.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var express = require("express");
var path = require("path");
const winston = require("winston");
// const expressWinston = require('express-winston');
let morgan = require("morgan");
var indexRouter = require("./routes/index");
const apiRouter = require("./routes/api");
const { handleErrors } = require("./helpers/error");
const fs = require("fs");
const config = require("./config");
const db = require("./db/database"); // opens the connection for the following routers
var app = express();
// create a write stream (in append mode)
var accessLogStream = fs.createWriteStream(config.accessLogFile, {
flags: "a",
});
// log only 4xx and 5xx responses to console
app.use(
morgan("dev", {
skip: function (req, res) {
return res.statusCode < 400;
},
})
);
app.use(morgan("common", { stream: accessLogStream }));
// app.use(expressWinston.logger({
// transports: [
// new winston.transports.Console({
// json: false,
// format: winston.format.combine(
// winston.format.colorize(),
// winston.format.simple(),
// winston.format.prettyPrint()
// )
// }),
// // new winston.transports.File({ filename: 'combined.log' })
// ],
// meta: true,
// expressFormat: true,
// colorize: true,
// }));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// app.use(express.static(path.join(__dirname, "public")));
app.use(express.static(path.join(__dirname, "client/build")));
app.use("/api", apiRouter);
// Serve static files from the React frontend app
// Anything that doesn't match the above, send back index.html
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname + "/client/build/index.html"));
});
app.use(handleErrors);
module.exports = app;