-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.js
59 lines (47 loc) · 1.37 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";
var config = require("./config/config");
var express = require('express'),
path = require('path'),
fs = require('fs');
var app = express();
// environment and port
var env = process.env.NODE_ENV || 'development';
var port;
if (config && config.http && config.http.port)
port = config.http.port;
else
port = 3000;
// app middleware/settings
app.engine('.html', require('ejs').__express);
app.enable('trust proxy')
.use(require('body-parser').json())
.use(require('body-parser').urlencoded({extended: false}))
.use(function(req,res,next){
res.locals.req = req;
next();
});
if (config && config.sitemap && config.sitemap.directory) {
app.use('/sitemap', express.static(config.sitemap.directory, {
setHeaders: function (res, path, stat) {
res.set("X-Robots-Tag", "noindex");
}
}));
}
app.use(express.static(__dirname + '/public'));
// development vs production
if (env == "development")
app.use(require('errorhandler')({dumpExceptions: true, showStack: true}));
else
app.use(require('errorhandler')());
// helpers and routes
app.locals.helpers = require("./app/helpers");
app.locals.config = require("./config/config");
require("./app/routes")(app);
// boot it up!
if (!module.parent) {
app.listen(port, function() {
console.log("Express server listening on port %s in %s mode", port, env);
});
}
else
exports.app = app;