adejs/utils/create-url.js

29 lines
540 B
JavaScript

let urls = {};
class Url {
constructor(url, view, name, method="GET") {
this.url = url;
this.view = view;
this.name = name;
this.method = method;
}
}
function getUrl(name) {
return urls[name].url;
}
module.exports = function(req, res, next) {
res.locals.getUrl = getUrl;
return next();
}
module.exports.getUrl = getUrl;
module.exports.url = function(url, viewName, urlName, method) {
let ret = new Url(url, viewName, urlName, method);
urls[urlName] = ret;
return ret;
}