2016-01-08 11:33:24 +00:00
|
|
|
var express = require('express'), path = require('path'), http = require('http'),
|
|
|
|
fx = require('./lib/fx'), btc = require('./lib/btc'), train = require('./lib/train'),
|
2016-02-01 00:22:50 +00:00
|
|
|
password = require('./lib/password') , clean = require('./lib/clean'), events = require('./lib/events'),
|
2016-03-01 00:18:53 +00:00
|
|
|
today = require('./lib/today'),
|
|
|
|
morgan = require('morgan'), cookieParser = require('cookie-parser'),session = require('express-session')
|
|
|
|
methodoverride = require('method-override'), bodyparser = require('body-parser'), errorhandler = require('errorhandler');
|
2015-08-04 14:07:01 +00:00
|
|
|
//train = require('lib/train')
|
|
|
|
/* ,submit = require('./routes/mongo/submit') */
|
|
|
|
;
|
|
|
|
var app = express();
|
|
|
|
GLOBAL.lastcheck = 0;
|
|
|
|
var btcCache = {}, fxCache = {} , trainCache = {};
|
|
|
|
|
2016-03-01 00:18:53 +00:00
|
|
|
//app.configure(function () {
|
|
|
|
app.set('port', process.env.PORT || 9000);
|
2016-01-08 14:53:49 +00:00
|
|
|
app.set('view engine', 'ejs');
|
2016-03-01 00:18:53 +00:00
|
|
|
app.use(morgan('dev'));
|
|
|
|
app.use(cookieParser('your secret here'));
|
|
|
|
app.use(session({
|
|
|
|
secret: '1234567890QWERTY', resave: false,
|
|
|
|
saveUninitialized: false
|
|
|
|
}));
|
2015-08-04 14:07:01 +00:00
|
|
|
/* 'default', 'short', 'tiny', 'dev' */
|
2016-03-01 00:18:53 +00:00
|
|
|
app.use(methodoverride());
|
2015-08-04 14:07:01 +00:00
|
|
|
|
2016-03-01 00:18:53 +00:00
|
|
|
app.use(bodyparser.urlencoded({extended: false}));
|
|
|
|
|
|
|
|
// parse application/json
|
|
|
|
app.use(bodyparser.json());
|
2015-08-04 14:07:01 +00:00
|
|
|
|
|
|
|
app.use(function (req, res, next) {
|
|
|
|
res.header("Access-Control-Allow-Origin", "*");
|
|
|
|
res.header("Access-Control-Allow-Headers", "X-Requested-With");
|
|
|
|
next();
|
|
|
|
});
|
2016-03-01 00:18:53 +00:00
|
|
|
// app.use(app.router);
|
2015-08-04 14:07:01 +00:00
|
|
|
app.use(express.static(path.join(__dirname, 'app')));
|
|
|
|
|
2016-03-01 00:18:53 +00:00
|
|
|
app.use(errorhandler({dumpExceptions: true, showStack: true}));
|
|
|
|
|
|
|
|
app.use('/btc', btc.doBTC);
|
2015-08-04 14:07:01 +00:00
|
|
|
|
|
|
|
app.use('/fx', fx.doFx);
|
|
|
|
|
|
|
|
app.use('/dbeglq', train.dbe_glq);
|
|
|
|
app.use('/glqdbe', train.glq_dbe);
|
2015-08-10 10:45:31 +00:00
|
|
|
app.use('/gettrains', train.getTrainTimes);
|
2016-01-08 11:33:24 +00:00
|
|
|
app.use('/getnexttraintimes', train.getNextTrainTimes);
|
2016-01-15 11:02:41 +00:00
|
|
|
app.use('/getroute', train.getRoute);
|
2015-08-04 14:07:01 +00:00
|
|
|
|
2015-08-19 10:20:23 +00:00
|
|
|
app.use('/generate', password.generate);
|
|
|
|
|
2016-01-08 11:33:24 +00:00
|
|
|
app.use('/cleanit', clean.cleanit);
|
|
|
|
|
2016-01-08 14:53:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
app.use('/events', events.getEvents);
|
2016-02-01 00:22:50 +00:00
|
|
|
app.get('/cinema/:id', events.getCinema);
|
|
|
|
|
|
|
|
app.get('/today', today.getToday);
|
2016-03-01 00:18:53 +00:00
|
|
|
app.get('/today/data', today.getData);
|
|
|
|
|
|
|
|
app.route('/clock')
|
|
|
|
.get(today.getClock);
|
2016-02-01 00:22:50 +00:00
|
|
|
|
2016-01-08 14:53:49 +00:00
|
|
|
|
2015-08-04 14:07:01 +00:00
|
|
|
app.use('/lot', function (req, res) {
|
|
|
|
var pg = require('pg');
|
|
|
|
|
|
|
|
var conString = "postgres://pguser:1V3D4m526i@localhost/silver";
|
|
|
|
console.log(conString);
|
|
|
|
|
|
|
|
|
|
|
|
var client = new pg.Client(conString);
|
|
|
|
var q = 'select * from lot order by d desc';
|
|
|
|
client.connect(function(err) {
|
|
|
|
if(err) {
|
|
|
|
return console.error('could not connect to postgres', err);
|
|
|
|
}
|
|
|
|
client.query(q, function(err, result) {
|
|
|
|
if(err) {
|
|
|
|
return console.error('error running query', err);
|
|
|
|
}
|
|
|
|
console.log(result.rows[0].theTime);
|
|
|
|
//output: Tue Jan 15 2013 19:12:47 GMT-600 (CST)
|
|
|
|
client.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-02-01 00:22:50 +00:00
|
|
|
|
|
|
|
app.get('/slack', function (req, res) {
|
|
|
|
res.render('pages/slack');
|
|
|
|
});
|
|
|
|
|
2016-02-18 11:01:53 +00:00
|
|
|
app.get('/temp', function (req, res) {
|
|
|
|
res.render('pages/temp');
|
|
|
|
});
|
|
|
|
|
2016-03-01 00:18:53 +00:00
|
|
|
//});
|
2015-08-04 14:07:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* create the server
|
|
|
|
*/
|
|
|
|
http.createServer(app).listen(app.get('port'), function () {
|
|
|
|
console.log("Express server listening on port " + app.get('port'));
|
|
|
|
});
|