forked from linnovate/mean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
express.js
71 lines (50 loc) · 1.89 KB
/
express.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
/* globals require */
'use strict';
/**
* Module dependencies.
*/
var mean = require('meanio'),
compression = require('compression'),
consolidate = require('consolidate'),
express = require('express'),
helpers = require('view-helpers'),
flash = require('connect-flash'),
modRewrite = require('connect-modrewrite'),
// seo = require('mean-seo'),
config = mean.getConfig(),
bodyParser = require('body-parser'),
helmet = require('helmet');
module.exports = function(app, db) {
app.use(bodyParser.json(config.bodyParser.json));
app.use(bodyParser.urlencoded(config.bodyParser.urlencoded));
app.use(helmet());
app.set('showStackError', true);
// Prettify HTML
app.locals.pretty = true;
// cache=memory or swig dies in NODE_ENV=production
app.locals.cache = 'memory';
// Should be placed before express.static
// To ensure that all assets and data are compressed (utilize bandwidth)
app.use(compression({
// Levels are specified in a range of 0 to 9, where-as 0 is
// no compression and 9 is best compression, but slowest
level: 9
}));
// Enable compression on bower_components
app.use('/bower_components', express.static(config.root + '/bower_components'));
app.use('/bundle', express.static(config.root + '/bundle'));
// Adds logging based on logging config in config/env/ entry
require('./middlewares/logging')(app, config.logging);
// assign the template engine to .html files
app.engine('html', consolidate[config.templateEngine]);
// set .html as the default extension
app.set('view engine', 'html');
// Dynamic helpers
app.use(helpers(config.app.name));
// Connect flash for flash messages
app.use(flash());
app.use(modRewrite([
'!^/api/.*|\\_getModules|\\.html|\\.js|\\.css|\\.swf|\\.jp(e?)g|\\.JP(E?)G|\\.PNG|\\.png|\\.ico|\\.gif|\\.svg|\\.eot|\\.ttf|\\.woff|\\.txt|\\.pdf$ / [L]'
]));
// app.use(seo());
};