@mvx/mvc
Version:
@mvx/mvc is mvc framework on server, base on koa, @tsdi frameworks
59 lines (57 loc) • 2.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RouteChecker = void 0;
var tslib_1 = require("tslib");
var ioc_1 = require("@tsdi/ioc");
var urlReg = /\/((\w|%|\.))+\.\w+$/;
var noParms = /\/\s*$/;
var hasParms = /\?\S*$/;
var subStart = /^\s*\/|\?/;
var RouteChecker = /** @class */ (function (_super) {
tslib_1.__extends(RouteChecker, _super);
function RouteChecker() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.assertUrlRegExp = urlReg;
return _this;
}
RouteChecker.prototype.isRoute = function (ctxUrl) {
return !this.assertUrlRegExp.test(ctxUrl);
};
RouteChecker.prototype.getReqRoute = function (ctx) {
var reqUrl = this.vaildify(ctx.url, true);
var config = ctx.mvcContext.getConfiguration();
if (config.routePrefix) {
return reqUrl.replace(config.routePrefix, '');
}
return reqUrl;
};
RouteChecker.prototype.vaildify = function (routePath, foreNull) {
if (foreNull === void 0) { foreNull = false; }
if (foreNull && routePath === '/') {
routePath = '';
}
if (noParms.test(routePath)) {
routePath = routePath.substring(0, routePath.lastIndexOf('/'));
}
if (hasParms.test(routePath)) {
routePath = routePath.substring(0, routePath.lastIndexOf('?'));
}
return routePath;
};
RouteChecker.prototype.isActiveRoute = function (ctx, route) {
var routeUrl = this.getReqRoute(ctx);
if (route === '' || route === routeUrl) {
return true;
}
return routeUrl.startsWith(route) && subStart.test(routeUrl.substring(route.length));
};
RouteChecker.ρAnn = function () {
return { "name": "RouteChecker", "params": { "isRoute": ["ctxUrl"], "getReqRoute": ["ctx"], "vaildify": ["routePath", "foreNull"], "isActiveRoute": ["ctx", "route"] } };
};
RouteChecker = tslib_1.__decorate([
ioc_1.Singleton()
], RouteChecker);
return RouteChecker;
}(ioc_1.IocCoreService));
exports.RouteChecker = RouteChecker;
//# sourceMappingURL=../sourcemaps/services/RouteChecker.js.map