-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (48 loc) · 1.54 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
import express from "express";
import bodyParser from "body-parser";
import compression from "compression";
import cookieParser from "cookie-parser";
import errorHandler from "errorhandler";
import morgan from "morgan";
import ace from "atlassian-connect-express";
import hbs from "express-hbs";
import path from "path";
import routes from "./routes";
import expressSession from "express-session";
import { v4 as uuid } from "uuid";
import handlbarsHelpers from "./lib/helpers";
const app = express();
const addon = ace(app);
const port = addon.config.port();
const PORT = process.env.PORT || port;
app.set("port", PORT);
handlbarsHelpers(hbs);
const viewsDir = __dirname + "/views";
app.engine("hbs", hbs.express4({ partialsDir: viewsDir }));
app.set("view engine", "hbs");
app.set("views", viewsDir);
const devEnv = app.get("env") == "development";
app.use(morgan(devEnv ? "dev" : "combined"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(compression());
app.use(
expressSession({
secret: process.env.session_secret,
resave: true,
saveUninitialized: true,
genid: function(req) {
return uuid();
}
})
);
app.use(addon.middleware());
const staticDir = path.join(__dirname, "public");
app.use(express.static(staticDir));
if (devEnv) app.use(errorHandler());
routes(app, addon);
app.listen(PORT, () => {
console.log("App server running at http://" + addon.config.localBaseUrl + ":" + PORT);
if (devEnv) addon.register();
});