70 lines
1.7 KiB
JavaScript
70 lines
1.7 KiB
JavaScript
const express = require('express');
|
|
const path = require('path');
|
|
const apicache = require('apicache');
|
|
const logger = require('log4js').getLogger('Server');
|
|
const weather = require('./server/weather');
|
|
const euronews = require('./server/euronews');
|
|
const foursquare = require('./server/foursquare');
|
|
|
|
logger.level = 'debug';
|
|
|
|
const app = express();
|
|
const port = process.env.PORT || 8110;
|
|
|
|
const sitePath = 'live';
|
|
|
|
apicache.options({ 'debug': true });
|
|
const cache = apicache.middleware;
|
|
|
|
app.use(express.static(path.join(__dirname, sitePath)));
|
|
|
|
app.get('/weather', cache('20 minutes'), (req, res) => {
|
|
if (req.query.hasOwnProperty('ll'))
|
|
weather.doGetOpenWeather(req.query.ll)
|
|
.then((d) => {
|
|
res.send(d);
|
|
}).catch((e) => {
|
|
logger.error(e);
|
|
res.status(500).send('There was an error!');
|
|
});
|
|
|
|
else {
|
|
// throw new Error('Weather: LL missing');
|
|
logger.warn('Weather: LL missing');
|
|
res.status(500).send('LL Missing');
|
|
}
|
|
});
|
|
|
|
app.get('/fsexplore', cache('30 minutes'), (req, res) => {
|
|
if (req.query.hasOwnProperty('ll'))
|
|
foursquare.doGetFourSquareExplore(req.query.ll)
|
|
.then((d) => {
|
|
res.send(d);
|
|
}).catch((e) => {
|
|
logger.error(e);
|
|
res.status(500).send('There was an error!');
|
|
});
|
|
|
|
else {
|
|
// throw new Error('Weather: LL missing');
|
|
logger.warn('FS: LL missing');
|
|
res.status(500).send('LL Missing');
|
|
}
|
|
});
|
|
|
|
app.get('/news', cache('20 minutes'), (req, res) => {
|
|
euronews.getEuroNews().then((d) => {
|
|
res.send(d);
|
|
}).catch((e) => {
|
|
logger.error(e);
|
|
res.status(500).send('There was an error!');
|
|
});
|
|
});
|
|
|
|
app.listen(port, (err) => {
|
|
if (err)
|
|
return logger.error('Server error:', err);
|
|
|
|
logger.info(`Jubilee Server is listening on ${port}`);
|
|
});
|