forked from adonisjs/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroup.js
More file actions
90 lines (79 loc) · 1.67 KB
/
group.js
File metadata and controls
90 lines (79 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict'
/**
* adonis-framework
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
const helpers = require('./helpers')
const domains = require('./domains')
const util = require('../../lib/util')
/**
* Route groups to keep configuration DRY for bunch of
* routes.
* @class
* @alias Route.Group
*/
class Group {
constructor (routes) {
this.routes = routes
}
/**
* @see module:Route~middlewares
*/
middlewares () {
helpers.appendMiddleware(
this.routes,
util.spread.apply(this, arguments)
)
return this
}
/**
* @see module:Route~middleware
*/
middleware () {
return this.middlewares.apply(this, arguments)
}
/**
* prefix group of routes with a given pattern
*
* @param {String} pattern
*
* @return {Object} - reference to this for chaining
*
* @example
* Route.group('...').prefix('/v1')
*
* @public
*/
prefix (pattern) {
helpers.prefixRoute(this.routes, pattern)
return this
}
/**
* add domain to group of routes. All routes inside the group
* will be matched on define domain
*
* @param {String} domain
* @return {Object} - reference to this for chaining
*
* @example
* Route.group('...').domain(':user.example.com')
*
* @public
*/
domain (domain) {
domains.add(helpers.makeRoutePattern(domain))
helpers.addDomain(this.routes, domain)
}
/**
* @see module:Route~formats
*/
formats (formats, strict) {
helpers.addFormats(this.routes, formats, strict)
return this
}
}
module.exports = Group