ethstats-server/lib/express.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

2015-06-10 04:04:17 +02:00
var express = require('express');
var app = express();
var path = require('path');
var bodyParser = require('body-parser');
// view engine setup
2015-07-29 19:15:45 +02:00
app.set('views', path.join(__dirname, (process.env.LITE === 'true' ? '../src-lite/views' : '../src/views')));
2015-06-10 04:04:17 +02:00
app.set('view engine', 'jade');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
2015-07-29 19:15:45 +02:00
app.use(express.static(path.join(__dirname, (process.env.LITE === 'true' ? '../dist-lite' : '../dist'))));
2015-06-10 04:04:17 +02:00
app.get('/', function(req, res) {
2015-07-29 19:15:45 +02:00
res.render('index');
2015-06-10 04:04:17 +02:00
});
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
// production error handler
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;