50 lines
1.1 KiB
JavaScript
50 lines
1.1 KiB
JavaScript
const express = require('express');
|
|
const path = require('path');
|
|
const logger = require('log4js').getLogger('Server');
|
|
|
|
|
|
const db = require('./server/db-connector').dbConnection;
|
|
const dbTestdata = require('./server/db-testdata')(db);
|
|
|
|
const nameGen = require('./server/name-gen');
|
|
|
|
logger.level = 'debug';
|
|
|
|
const app = express();
|
|
const port = process.env.PORT || 9000;
|
|
|
|
const sitePath = 'live';
|
|
|
|
app.use(express.static(path.join(__dirname, sitePath)));
|
|
|
|
// app.get('/weather', cache('15 minutes'), (req, res) => {
|
|
|
|
const asyncMiddleware = fn =>
|
|
(req, res, next) => {
|
|
Promise.resolve(fn(req, res, next))
|
|
.catch(next);
|
|
};
|
|
|
|
app.get('/data', (req, res) => {
|
|
dbTestdata.sqlGetSimpleList().then((d) => {
|
|
res.send(d);
|
|
}).catch((e) => {
|
|
logger.error(e);
|
|
});
|
|
});
|
|
|
|
app.listen(port, (err) => {
|
|
if (err)
|
|
return logger.error('Server error:', err);
|
|
|
|
logger.info(`Test Server is listening on ${port}`);
|
|
|
|
const i = setInterval(()=>{
|
|
dbTestdata.sqlInsertData(nameGen.gen()).then((d) => {
|
|
logger.debug(d);
|
|
}).catch((e) => {
|
|
logger.error(e);
|
|
});
|
|
}, 15000)
|
|
});
|