const express = require('express'); const path = require('path'); const apicache = require('apicache'); const logger = require('log4js').getLogger('Server'); const weather = require('./server/weather'); logger.level = 'debug'; const app = express(); const port = process.env.PORT || 3000; const sitePath = 'src'; apicache.options({ 'debug': true }); const cache = apicache.middleware; app.use(express.static(path.join(__dirname, sitePath))); app.get('/weather', cache('20 minutes'), (req, res) => { weather.doGetOpenWeather() .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(`Weather Server is listening on ${port}`); });