2018-11-30 10:11:36 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { Router } = require('express');
|
|
|
|
/**
|
|
|
|
* Base class for Controllers to standardize binding to express Router.
|
|
|
|
*/
|
|
|
|
class Controller {
|
|
|
|
constructor() {
|
|
|
|
const router = Router();
|
|
|
|
this.app = router;
|
|
|
|
}
|
|
|
|
|
|
|
|
get(path, handler) {
|
|
|
|
this.app.get(path, handler.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
post(path, handler) {
|
|
|
|
this.app.post(path, handler.bind(this));
|
|
|
|
}
|
|
|
|
|
2018-11-30 11:11:12 +01:00
|
|
|
put(path, handler) {
|
|
|
|
this.app.put(path, handler.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(path, handler) {
|
|
|
|
this.app.delete(path, handler.bind(this));
|
|
|
|
}
|
|
|
|
|
2018-12-03 08:59:13 +01:00
|
|
|
use(path, router) {
|
|
|
|
this.app.use(path, router);
|
|
|
|
}
|
|
|
|
|
|
|
|
get router() {
|
2018-11-30 10:11:36 +01:00
|
|
|
return this.app;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Controller;
|