I am doing some routing stuff and I am also using express so I'll need request and response later in controllers but I wanted to just inherit it from base controller instead of typing it in each new instance as arguments so here I've got code when I am including two controllers
loadController(controller, method)
{
var Base = require.main.require("./App/Base/Controller"),
BaseController = new Base(this.req, this.res),
NewController = require.main.require("./App/Controllers/" + controller),
Controller = new NewController();
Controller[method]();
}
Here's the base controller:
module.exports = class Controller{
constructor(req, res)
{
this.req = req;
this.res = res;
}
}
And what I want to ask is it possible that I can get this.req
and this.res
in any other controllers included such as:
var Controller = require.main.require("./App/Base/Controller");
module.exports = class indexController extends Controller{
indexAction()
{
// I want `this.req` and `this.res` there
}
}