When my server receives a request, I create a dispatcher which creates a router and ask to my router the controller that my dispatcher needs, so I send a URL to my router and with an array with every path. My router sends the controller to my dispatcher and my dispatcher calls the controlle index() func...
So my problem is, when I initialize my controllers, my controllers are overwritten by the last controller. Could someone tell me why?
This is my router, I've created a small code with logs to show the problem:
function Router(){
log(colors.green+"Router initialization...")
this.indexController = new (require("../controllers/index"))();
log(this.indexController.constructor.name);
this.notFoundController = new (require("../controllers/notFound"))();
log(this.notFoundController.constructor.name);
this.publicController = new (require("../controllers/public"))();
log(this.publicController.constructor.name);
this.faviconController = new (require("../controllers/favicon"))();
log(this.faviconController.constructor.name);
this.registerController = new (require("../controllers/register"))();
log(this.registerController.constructor.name);
log(colors.green+"Router initialization successful")
log(this.indexController.constructor.name);
log(this.notFoundController.constructor.name);
log(this.publicController.constructor.name);
log(this.faviconController.constructor.name);
log(this.registerController.constructor.name);
}
console logs :
Log(21:9:4): Router initialization...
Log(21:9:4): IndexController
Log(21:9:4): NotFoundController
Log(21:9:4): PublicController
Log(21:9:4): FaviconController
Log(21:9:4): RegisterController
Log(21:9:4): Router initialization successful
Log(21:9:4): RegisterController
Log(21:9:4): RegisterController
Log(21:9:4): RegisterController
Log(21:9:4): RegisterController
Log(21:9:4): RegisterController
Why are my variables overwritten?
register.js:
function RegisterController() {}
RegisterController.prototype = Controller.prototype;
RegisterController.prototype.constructor = RegisterController;
RegisterController.prototype.index = function(content) {
if (content.req.method == "POST") {
content.res.writeHeader(200, {
"Content-Type": "text/html"
});
content.res.write(content.datas);
content.res.end();
} else {
this.render.call(content, "register");
}
}
module.exports = RegisterController;