var express = require('express'), path = require('path'), http = require('http'), morgan = require(
    'morgan'), cookieParser = require('cookie-parser'), session = require(
    'express-session'), methodoverride = require('method-override'), bodyparser = require(
    'body-parser'), errorhandler = require('errorhandler');

var logger = require('log4js').getLogger();
var app = express();
GLOBAL.lastcheck = 0;

//app.configure(function () {
app.set('port', process.env.PORT || 9000);
app.set('view engine', 'ejs');
app.use(morgan('dev'));
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, 'app')));

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

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