-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
30 lines (27 loc) · 743 Bytes
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var db = require('./db.js');
var token = require('./token.js');
function authenticate(req, res, next) {
try {
if (req.headers.apptokenizer === token) {
var user = 'webapp';
next();
} else {
res.status(401).json({
message: "Incorrect token credentials"
});
}
} catch (err) {
console.log(err);
res.status(401).json({
message: "Incorrect token credentials"
});
}
}
module.exports.route = (app) => {
app.get('/', authenticate, db.orm.getTables);
app.get('/:table', authenticate, db.orm.all);
app.get('/:table/:id', authenticate, db.orm.findById);
app.post('/:table', authenticate, db.orm.add);
app.put('/:table/:id', authenticate, db.orm.update);
app.delete('/:table/:id', authenticate, db.orm.delete);
}