webio-node/route/api/index.js

35 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-03-22 05:35:45 +00:00
const express = require('express');
const router = express.Router();
const errMng = require('../../includes/errorManager');
router
.get('/', (req, res) => {
res.send({ name: 'WebIO API System' });
})
.use('/system', require('./system.js'))
.use('/log', require('./log.js'))
.use('/leone', require('./leone.js'))
.use('/iogroup', require('./iogroup.js'))
.use('/iocmd', require('./iocmd.js'))
.use('/schedule', require('./schedule.js'))
.use('/dio', require('./dio.js'))
.use('/link', require('./link.js'))
.use('/modbus', require('./modbus.js'));
// api error handler
router.use((err, req, res, n) => {
if ('db' in res && typeof res.db == 'object' && 'close' in res.db && typeof res.db.close == 'function') res.db.close();
let lngs = req.headers['accept-language'].split(',');
let lng = null;
if (lngs.length > 0) {
lng = lngs[0].substring(0, 2);
}
res.send({
errorCode: (typeof err != 'string' ? err.toString() : err),
message: errMng(err, lng),
status: 0
});
})
module.exports = router;