Comparing version 2.2.20 to 2.2.21
@@ -40,2 +40,3 @@ /** | ||
declare const RouteMiddleWare: (options: MiddleWareOptions) => (target: Router, key: string) => void; | ||
export { MiddleWare, GET, PUT, POST, PATCH, DELETE, RouteMiddleWare }; | ||
declare const Use: (path: string, ...middleWares: MiddleWareInterface[]) => (constructor: Function) => void; | ||
export { MiddleWare, GET, PUT, POST, PATCH, DELETE, RouteMiddleWare, Use }; |
@@ -73,1 +73,8 @@ "use strict"; | ||
exports.RouteMiddleWare = RouteMiddleWare; | ||
const Use = (path, ...middleWares) => { | ||
return (constructor) => { | ||
var _a, _b; | ||
(_b = (_a = constructor.prototype) === null || _a === void 0 ? void 0 : _a.use) === null || _b === void 0 ? void 0 : _b.call(_a, path, ...middleWares); | ||
}; | ||
}; | ||
exports.Use = Use; |
@@ -101,3 +101,3 @@ /// <reference types="node" /> | ||
cors?: CorsInterface; | ||
use(func: MiddleWareInterface): this; | ||
use(path: string, func: MiddleWareInterface): this; | ||
build(): this; | ||
@@ -104,0 +104,0 @@ init(): this; |
@@ -41,3 +41,3 @@ /** | ||
}); | ||
use(func: MiddleWareInterface): this; | ||
use(path: string, ...middleWares: MiddleWareInterface[]): this; | ||
build(): this; | ||
@@ -44,0 +44,0 @@ parseTempMiddleWares(): void; |
@@ -24,2 +24,3 @@ "use strict"; | ||
const common_1 = require("./common"); | ||
const url_pattern_1 = __importDefault(require("url-pattern")); | ||
class Router { | ||
@@ -61,9 +62,22 @@ constructor(options) { | ||
this.statics = this.statics || []; | ||
// this.cors = this.cors || { | ||
// } | ||
this.staticFolder = this.options.staticFolder || this.staticFolder; | ||
this.parseTempMiddleWares(); | ||
} | ||
use(func) { | ||
this.globalMiddleWares.push(func); | ||
use(path, ...middleWares) { | ||
this.globalMiddleWares = this.globalMiddleWares || []; | ||
const pattern = new url_pattern_1.default(path); | ||
const applyMiddleWares = (comingMiddleWares) => { | ||
comingMiddleWares.map((func) => { | ||
const middleWare = (req, res, next) => { | ||
if (pattern.match(req.pathname)) { | ||
func(req, res, next); | ||
} | ||
else { | ||
return next(); | ||
} | ||
}; | ||
this.globalMiddleWares.push(middleWare); | ||
}); | ||
}; | ||
applyMiddleWares(middleWares); | ||
return this; | ||
@@ -70,0 +84,0 @@ } |
{ | ||
"name": "grandjs", | ||
"version": "2.2.20", | ||
"version": "2.2.21", | ||
"description": "A backend framework for solid web apps based on node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
259697
5639