-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
67 lines (52 loc) · 1.68 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
63
64
65
66
67
/**
* Module dependencies.
*/
var express = require('express'),
nunjucks = require('nunjucks'),
bodyParser = require('body-parser'),
logger = require('morgan'),
path = require('path'),
Contentstack = require('contentstack'),
cookieParser = require('cookie-parser');
var errorHandler = require('express-error-handler');
var bodyParser = require('body-parser');
var env = process.env.NODE_ENV || 'default',
_dirname = process.env.SITE_PATH ? path.resolve(process.env.SITE_PATH) : process.cwd(),
_env;
// load environment based configurations
var _path = path.join(_dirname, 'config');
if (env === 'default') _env = require(path.join(_path, 'default'));
else _env = require(path.join(_path, env));
// load globals
global['config'] = _env;
global['Stack'] = Contentstack.Stack(config.contentstack.api_key, config.contentstack.delivery_token, config.contentstack.environment);
var app = express();
app.enable('trust proxy');
// Client side pages to fall under ~/views directory
app.set('views', path.join(__dirname, 'views'));
// Setting Nunjucks as default view
nunjucks.configure('views', {
autoescape: true,
express: app,
});
app.set('view engine', 'html');
app.use(logger('dev'));
app.use(
bodyParser.urlencoded({
extended: true,
})
);
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'public')));
app.use(cookieParser());
// Routes
require('./routes')(app);
// After all your routes...
// Pass a 404 into next(err)
//app.use( errorHandler.httpError(404) );
// } catch (error) {
// console.error('Did not find configuration for the specified environment');
// console.error(error);
// console.error('exiting!');
// }
module.exports = app;