-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
53 lines (42 loc) · 1.34 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
const path = require('path'),
express = require('express'),
compression = require('compression'),
exphbs = require('express-handlebars'),
bodyParser = require('body-parser'),
sassMiddleware = require('node-sass-middleware'),
babelify = require('express-babelify-middleware'),
helpers = require(__dirname + '/helpers/general.js'),
app = express();
app.use(compression());
app.use(sassMiddleware({
// debug: true,
src: __dirname + '/src',
dest: path.join(__dirname, 'public'),
outputStyle: 'compressed'
}));
app.use(express.static('public'));
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use('/js/', babelify('src/scripts/', {
minify: true
}));
app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('views', __dirname + '/views');
app.set('view engine', 'handlebars');
app.use(function(req, res, next){
if (req.headers['x-forwarded-proto'].indexOf('https') === -1){
return res.redirect('https://' + req.headers.host + req.url);
}
else{
return next();
}
});
app.use('/', require('./routes/index.js'))
app.use('/image', require('./routes/image.js'))
app.use('/stats', require('./routes/stats.js'))
app.get('/js/helpers.js', function (req, res) {
res.sendFile(path.join(__dirname + '/helpers/general.js'));
});
module.exports = app;