-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
59 lines (50 loc) · 1.69 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
"use strict";
// config
const configManager = require("./config-manager.js");
if (!configManager.exists()) {
console.error("Could not find configuration file 'config.json'. Aborting...");
process.exit(1);
}
const config = configManager.load();
const http = require("http");
const express = require("express");
const path = require("path");
const flash = require("connect-flash-plus");
// const favicon = require("serve-favicon");
const logger = require("morgan");
const methodOverride = require("method-override");
const session = require("express-session");
const bodyParser = require("body-parser");
// const multer = require("multer");
const errorHandler = require("errorhandler");
const app = express();
const registerRoutes = require("./routes/routes.js");
const hbs = require("hbs");
const passport = require("passport");
const sessionSettings = {
secret: "muhbigsecret",
cookie: {},
saveUninitialized: true,
resave: false
};
// register all partials from directory.
hbs.registerPartials("./views/partials");
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "hbs");
// app.use(favicon(path.join(__dirname, "/public/favicon.ico")));
app.use(logger("dev"));
app.use(methodOverride());
app.use(session(sessionSettings));
app.use(flash());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// app.use(multer({ dest: './uploads' }));
app.use(express.static(path.join(__dirname, "public")));
app.use(passport.initialize());
app.use(passport.session());
registerRoutes(app, passport);
app.use(errorHandler());
const port = configManager.get(config, "port");
http.createServer(app).listen(port, () => {
console.log("Server started on port " + port + ".");
});