var express = require('express'), path = require('path'), http = require('http'), ejs = require('ejs'), morgan = require('morgan'), cookieparser = require('cookie-parser'), session = require('express-session');
var methodoverride = require('method-override'), bodyparser = require('body-parser'), errorhandler = require('errorhandler');
var app = express();
var lastcheck = 0;
var btcCache = {}, fxCache = {};

//app.configure(function () {
app.set('port', 9002);
app.use(morgan('combined'));
app.use(cookieparser('your secret here'));
app.use(session({
  secret: '1234567890QWERTY', resave: false,
  saveUninitialized: false
}));
/* 'default', 'short', 'tiny', 'dev' */
app.use(methodoverride());

app.use(bodyparser.urlencoded({extended: false}));

// parse application/json
app.use(bodyparser.json());

app.use(function (req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  next();
});
//app.use(app.router);
app.use(express.static(path.join(__dirname, 'dist')));

app.use(errorhandler({dumpExceptions: true, showStack: true}));



//});

/**
 * create the server
 */
http.createServer(app).listen(app.get('port'), function () {
  console.log("Express server listening on port " + app.get('port'));
});
