adding caching
This commit is contained in:
parent
c6d854d2e0
commit
291cedeb17
@ -1,6 +1,6 @@
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
const server = require('http').createServer();
|
||||
const http = require('http');
|
||||
|
||||
const fx = require('./lib/fx');
|
||||
const btc = require('./lib/btc');
|
||||
@ -12,6 +12,7 @@ const events = require('./lib/events');
|
||||
const morgan = require('morgan');
|
||||
const cookieParser = require('cookie-parser');
|
||||
const session = require('express-session');
|
||||
const apicache = require('apicache');
|
||||
|
||||
const methodoverride = require('method-override');
|
||||
const bodyparser = require('body-parser');
|
||||
@ -24,13 +25,14 @@ const busEmitter = new Events.EventEmitter();
|
||||
|
||||
// busEmitter.on('update', today.broadcast);
|
||||
|
||||
const WebSocketServer = require('ws').Server;
|
||||
const wss = new WebSocketServer({ 'server': server });
|
||||
const WebSocket = require('ws');
|
||||
// const wss = new WebSocketServer({ 'server': server });
|
||||
|
||||
const SocketHandler = require('./lib/wshandlerv2');
|
||||
|
||||
const webSocket = new SocketHandler(busEmitter, wss);
|
||||
// const webSocket = new SocketHandler(busEmitter, wss);
|
||||
|
||||
btc.setEmitter(busEmitter);
|
||||
// today.setEmitter(busEmitter);
|
||||
|
||||
// train = require('lib/train')
|
||||
@ -78,57 +80,32 @@ app.use(express.static(path.join(__dirname, 'app')));
|
||||
|
||||
app.use(errorhandler({ 'dumpExceptions': true, 'showStack': true }));
|
||||
|
||||
app.use('/btc', btc.doBTC);
|
||||
app.use('/balance', btc.doBalance);
|
||||
apicache.options({ 'debug': true });
|
||||
const cache = apicache.middleware;
|
||||
|
||||
app.use('/fx', fx.doFx);
|
||||
app.use('/btc', cache('15 minutes'), btc.doBTC);
|
||||
app.use('/balance', cache('15 minutes'), btc.doBalance);
|
||||
|
||||
app.use('/fx', cache('15 minutes'), fx.doFx);
|
||||
|
||||
app.use('/dbeglq', train.dbe_glq);
|
||||
app.use('/glqdbe', train.glq_dbe);
|
||||
app.use('/gettrains', train.getTrainTimes);
|
||||
app.use('/getnexttraintimes', train.getNextTrainTimes);
|
||||
app.use('/getnexttraintimes', cache('1 minute'), train.getNextTrainTimes);
|
||||
app.use('/getroute', train.getRoute);
|
||||
|
||||
app.use('/generate', password.generate);
|
||||
|
||||
app.use('/cleanit', clean.cleanit);
|
||||
|
||||
app.use('/events', events.getEvents);
|
||||
app.get('/cinema/:id', events.getCinema);
|
||||
|
||||
// app.get('/today', today.getToday);
|
||||
// app.get('/today/data', today.getData);
|
||||
|
||||
// app.route('/clock').get(today.getClock);
|
||||
app.use('/events', cache('6 hours'), events.getEvents);
|
||||
app.get('/cinema/:id', cache('6 hours'), events.getCinema);
|
||||
|
||||
app.route('/poly').get(polys);
|
||||
|
||||
/* app.use('/lot', function(req, res) {
|
||||
const pg = require('pg');
|
||||
|
||||
const conString = 'postgres://pguser:1V3D4m526i@localhost/silver';
|
||||
console.log(conString);
|
||||
|
||||
const client = new pg.Client(conString);
|
||||
const 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();
|
||||
});
|
||||
});
|
||||
});*/
|
||||
|
||||
app.get('/slack', function(req, res) {
|
||||
res.render('pages/slackV2-min');
|
||||
// res.render('pages/slackV2');
|
||||
// res.render('pages/slackV2-min');
|
||||
res.render('pages/slackV2');
|
||||
});
|
||||
|
||||
app.get('/temp', function(req, res) {
|
||||
@ -226,8 +203,15 @@ http.createServer(app).listen(app.get('port'), function () {
|
||||
//console.log("Express server listening on port " + app.get('port'));
|
||||
});
|
||||
*/
|
||||
const server = http.createServer(app);
|
||||
|
||||
server.on('request', app);
|
||||
let wss;
|
||||
let webSocket;
|
||||
wss = new WebSocket.Server({ server });
|
||||
|
||||
webSocket = new SocketHandler(busEmitter, wss);
|
||||
|
||||
// server.on('request', app);
|
||||
server.listen(port, () => {
|
||||
logger.info(`New server listening on ${ server.address().port}`);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user