-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (60 loc) · 1.73 KB
/
index.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
require("dotenv").config();
const express = require("express");
const app = express();
const expressHbs = require("express-handlebars");
const paginate = require("express-handlebars-paginate");
const morgan = require("morgan");
const bodyParser = require("body-parser");
const cookie = require("cookie-parser");
const session = require("express-session");
const flash = require("connect-flash");
const methodOverride = require("method-override");
require("./controllers/helper").helper;
const poolConnection = require("./models/index");
const router = require("./routes");
app.engine(
"hbs",
expressHbs({
extname: "hbs",
defaultLayout: "layouts",
layoutsDir: __dirname + "/views/layouts/",
partialsDir: __dirname + "/views/partials/",
helpers: {
paginate: paginate.createPagination,
},
}),
);
app.use(morgan("dev"));
app.use(flash());
app.set("view engine", "hbs");
app.use(bodyParser.json());
app.use(cookie());
app.use(methodOverride("_method"));
app.use(
bodyParser.urlencoded({
extended: false,
}),
);
app.use(
session({
cookie: { httpOnly: true, maxAge: 30 * 24 * 60 * 60 * 1000 },
secret: "secret",
saveUninitialized: false,
resave: false,
}),
);
app.set("port", process.env.PORT || 3000);
app.use("/public", express.static(__dirname + "/public"));
app.use("/", router.user);
app.use("/projects", router.project);
app.listen(app.get("port"), () => {
poolConnection.getConnection((err, connection) => {
if (err) {
console.error("[ERROR]:::: err", err);
} else {
console.log(`Database connected with threadId: ${connection.threadId}`);
}
});
console.log(`Server is running on port ${app.get("port")}`);
});
app.get("*", (req, res) => res.send("Page Not found 404"));