adejs/utils/create-url.js

29 lines
540 B
JavaScript
Raw Normal View History

2017-09-23 11:02:29 +02:00
let urls = {};
2017-09-23 11:39:42 +02:00
class Url {
2017-09-23 18:20:56 +02:00
constructor(url, view, name, method="GET") {
2017-09-23 11:39:42 +02:00
this.url = url;
this.view = view;
this.name = name;
2017-09-23 18:20:56 +02:00
this.method = method;
2017-09-23 11:39:42 +02:00
}
}
function getUrl(name) {
return urls[name].url;
}
2017-09-23 11:02:29 +02:00
module.exports = function(req, res, next) {
2017-09-23 11:39:42 +02:00
res.locals.getUrl = getUrl;
2017-09-23 11:02:29 +02:00
return next();
}
2017-09-23 11:39:42 +02:00
module.exports.getUrl = getUrl;
2017-09-23 11:02:29 +02:00
2017-09-23 18:20:56 +02:00
module.exports.url = function(url, viewName, urlName, method) {
let ret = new Url(url, viewName, urlName, method);
2017-09-23 11:02:29 +02:00
urls[urlName] = ret;
return ret;
}