24 lines
503 B
JavaScript
24 lines
503 B
JavaScript
class Endpoint {
|
|
constructor(method, url, controller) {
|
|
this.method = method
|
|
this.url = url
|
|
this.controller = controller
|
|
this.middlewares = []
|
|
}
|
|
|
|
addMiddleware(middleware) {
|
|
this.middlewares.push(middleware)
|
|
}
|
|
|
|
apply(router) {
|
|
const method = this.method,
|
|
url = this.url
|
|
const middlewares = this.middlewares,
|
|
controller = this.controller
|
|
const params = [url, ...middlewares, controller]
|
|
router[method](...params)
|
|
}
|
|
}
|
|
|
|
module.exports = Endpoint
|