-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
48 lines (39 loc) · 1.44 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
var express = require('express');
var exphbs = require('express3-handlebars');
var fs = require('fs');
var path = require('path');
var _ = require('lodash');
var config = require('./lib/util/config');
var survey = require('./lib/survey/survey');
var logger = require('./lib/util/logger');
var handlebarsHelpers = require('./lib/util/handlebarsHelpers');
var app = express();
var publicDir = path.join(__dirname, 'public', 'dist');
var templatesDir = path.join(publicDir, 'handlebars');
var layoutsDir = path.join(templatesDir, 'layouts');
var viewsDir = path.join(templatesDir, 'views');
app.disable('x-powered-by');
app.post('/api/survey', survey.trigger);
app.engine('handlebars', exphbs({
defaultLayout: 'main',
layoutsDir: layoutsDir,
partialsDir: viewsDir,
helpers: handlebarsHelpers
}));
app.set('view engine', 'handlebars');
app.set("views", viewsDir);
app.disable('view cache');
app.get('/', survey.display);
app.use(app.router);
app.use('/', express.static(publicDir));
app.use(function(err, req, res, next){
res.status(500).sendfile(path.join(publicDir, 'html', '500.html'));
logger.error('Internal server error: %s', err.message);
});
app.use(function(req, res, next){
res.status(404).sendfile(path.join(publicDir, 'html', '404.html'));
});
app.listen(config.server.port, config.server.host, function(err) {
if (err) logger.die('Error starting RepoCop: %s', err.message);
process.send({ type: 'started' });
});