SilvrAPI/app.js

74 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-01-07 09:14:10 +00:00
var express = require('express');
GLOBAL.lastcheck = {"btc": 0, "fx": 0};
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
2015-11-08 22:50:16 +00:00
var routes = require('./routes/index');
2016-01-07 09:14:10 +00:00
var users = require('./routes/users');
2015-11-08 22:50:16 +00:00
var timeroute = require('./routes/time');
2016-01-07 09:14:10 +00:00
var btcroute = require('./routes/btc');
var temproute = require('./routes/temp');
var weightroute = require('./routes/weight');
2015-11-08 22:50:16 +00:00
var app = express();
// view engine setup
2016-01-07 09:14:10 +00:00
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
2015-11-08 22:50:16 +00:00
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
2016-01-07 09:14:10 +00:00
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
2015-11-08 22:50:16 +00:00
2016-01-07 09:14:10 +00:00
app.use('/', routes);
2015-11-08 22:50:16 +00:00
//app.use('/users', users);
2016-01-07 09:14:10 +00:00
app.use('/time', timeroute);
app.use('/btc', btcroute);
app.use('/temp',temproute);
app.use('/weight',weightroute);
2015-11-08 22:50:16 +00:00
// catch 404 and forward to error handler
2016-01-07 09:14:10 +00:00
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
2015-11-08 22:50:16 +00:00
2016-01-07 09:14:10 +00:00
// error handlers
// development error handler
2016-01-07 09:09:48 +00:00
// will print stacktrace
2016-01-07 09:14:10 +00:00
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
2016-01-07 09:09:48 +00:00
});
2016-01-07 09:14:10 +00:00
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
2015-11-08 22:50:16 +00:00
});
module.exports = app;