-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
62 lines (49 loc) · 1.59 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
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 http from 'http';
import path from 'path';
import * as pg from 'pg';
import helmet from 'helmet';
import nocache from 'nocache';
import setcache from './middleware/setcache';
import routes from './routes';
import { addServerSideRendering } from './server-side-rendering';
import aceConfig from './aceConfig';
const app = express();
const addon = ace(app, aceConfig);
const port = addon.config.port();
app.set('port', port);
const devEnv = app.get('env') === 'development';
app.use(morgan(devEnv ? 'dev' : 'combined'));
const viewsDir = path.join(__dirname, 'views');
const handlebarsEngine = hbs.express4({ partialsDir: viewsDir });
app.engine('hbs', handlebarsEngine);
app.set('view engine', 'hbs');
app.set('views', viewsDir);
addServerSideRendering(app, handlebarsEngine);
app.use(helmet.hsts({
maxAge: 31536000,
includeSubDomains: false
}));
app.use(helmet.referrerPolicy({
policy: ['origin']
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(compression());
app.use(addon.middleware());
const staticDir = path.join(__dirname, 'public');
app.use(express.static(staticDir));
app.use(setcache());
if (devEnv) app.use(errorHandler());
routes(app, addon);
http.createServer(app).listen(port, () => {
if (devEnv) addon.register();
});