-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
72 lines (59 loc) · 1.81 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
62
63
64
65
66
67
68
69
70
71
72
const express = require("express");
const app = express();
//const enforce = require('express-sslify');
const bodyParser = require("body-parser");
//session code
const cookieParser = require("cookie-parser");
const session = require("express-session");
const path = require("path");
//morgan logger
const morgan = require("morgan");
// Use enforce.HTTPS({ trustProtoHeader: true }) in case you are behind
// a load balancer (e.g. Heroku). See further comments below
//app.use(enforce.HTTPS({ trustProtoHeader: true}));
app.use(cookieParser());
app.use(
session({
secret: "secr3",
resave: false,
saveUninitialized: false,
maxAge: 24 * 60 * 60 * 1000,
})
);
//end of session code
app.use(bodyParser.urlencoded({ extended: true }));
//app.set("view engine", "ejs");
app.use(express.static("public"));
//app.use(express.static("views"));
//additional
//app.set('views', path.join(__dirname, 'views'));
//app.set('view engine', 'ejs');
if (process.env.NODE_ENV === "production") {
const rfs = require("rotating-file-stream");
// create a rotating write stream
const accessLogStream = rfs.createStream("access.log", {
interval: "1d", // rotate daily
path: path.join(__dirname, "logs"),
});
app.use(
morgan(
"[:remote-addr] [:remote-user] [:date[clf]] [:method :url] [:status] [:res[content-length]] [:referrer] [:user-agent]",
{
stream: accessLogStream,
skip: (req, res) => {
return req.url.startsWith("/static");
},
}
)
);
} else {
app.use(morgan("dev"));
}
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
//app.use(express.static(path.join(__dirname, 'public')));
const formData = require("express-form-data");
app.use(formData.parse());
global.__basedir = __dirname;
module.exports = app;