2023-12-22 20:13:25 +00:00
|
|
|
// router.js
|
|
|
|
// Namhyeon Go <abuse@catswords.net>
|
|
|
|
// https://github.com/gnh1201/welsonjs
|
|
|
|
function RouteModel(path, callback) {
|
|
|
|
this.path = path;
|
|
|
|
this.callback = callback;
|
|
|
|
}
|
|
|
|
|
2023-10-30 07:11:51 +00:00
|
|
|
function RouterObject() {
|
2023-12-22 20:13:25 +00:00
|
|
|
var routes = [];
|
2023-10-30 07:11:51 +00:00
|
|
|
|
2023-12-22 20:13:25 +00:00
|
|
|
this.render = function(filename, data) {};
|
2023-10-30 07:11:51 +00:00
|
|
|
this.setRender = function(render) {
|
|
|
|
this.render = render;
|
2023-12-22 20:13:25 +00:00
|
|
|
};
|
2023-10-30 07:11:51 +00:00
|
|
|
this.add = function(path, callback) {
|
2023-12-22 20:13:25 +00:00
|
|
|
routes.push(new RouteModel(path, callback));
|
|
|
|
};
|
2023-10-30 07:11:51 +00:00
|
|
|
this.go = function(path) {
|
2023-12-22 20:13:25 +00:00
|
|
|
var model = routes.find(function(x) {
|
2023-10-30 07:11:51 +00:00
|
|
|
return (x.path == path);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (typeof model !== "undefined") {
|
2024-03-20 12:12:59 +00:00
|
|
|
//try {
|
2023-10-30 07:11:51 +00:00
|
|
|
model.callback(this.render);
|
2024-03-20 12:12:59 +00:00
|
|
|
//} catch (e) {
|
|
|
|
// console.error(path, e.message);
|
|
|
|
//}
|
2023-10-30 07:11:51 +00:00
|
|
|
}
|
2023-12-22 20:13:25 +00:00
|
|
|
};
|
2023-10-30 07:11:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.Router = new RouterObject();
|
|
|
|
|
2023-12-22 20:13:25 +00:00
|
|
|
exports.VERSIONINFO = "URI Router (router.js) version 0.1.1";
|
2023-10-30 07:11:51 +00:00
|
|
|
exports.AUTHOR = "abuse@catswords.net";
|
|
|
|
exports.global = global;
|
|
|
|
exports.require = global.require;
|