29 lines
738 B
JavaScript
29 lines
738 B
JavaScript
const express = require('express');
|
|
const path = require('path');
|
|
const apicache = require('apicache');
|
|
const logger = require('log4js').getLogger('Server');
|
|
|
|
const train = require('./server/lib/train');
|
|
logger.level = 'debug';
|
|
|
|
const app = express();
|
|
const port = process.env.PORT || 8100;
|
|
|
|
const sitePath = 'live';
|
|
|
|
apicache.options({ 'debug': true });
|
|
const cache = apicache.middleware;
|
|
|
|
app.use(express.static(path.join(__dirname, sitePath)));
|
|
|
|
app.use('/gettrains', train.getTrainTimes);
|
|
app.use('/getnexttraintimes', train.getNextTrainTimes);
|
|
app.use('/getroute', train.getRoute);
|
|
|
|
app.listen(port, (err) => {
|
|
if (err)
|
|
return logger.error('Server error:', err);
|
|
|
|
logger.info(`TrainTime Server is listening on ${port}`);
|
|
});
|