Skip to content

Commit e09a167

Browse files
committed
minor routes registration cleanup
1 parent f6cfd1e commit e09a167

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const restana = require('restana')
33
const pump = require('pump')
44
const toArray = require('stream-to-array')
55
const defaultProxyHandler = (req, res, url, proxy, proxyOpts) => proxy(req, res, url, proxyOpts)
6+
const DEFAULT_METHODS = require('restana/libs/methods')
67

78
const gateway = (opts) => {
89
opts = Object.assign({
@@ -55,9 +56,22 @@ const gateway = (opts) => {
5556
// populating timeout config
5657
route.timeout = route.timeout || opts.timeout
5758

58-
// registering route handler
59-
const methods = route.methods || ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT', 'OPTIONS']
60-
server.route(methods, route.prefix + route.pathRegex, handler(route, proxy, proxyHandler), null, route.middlewares)
59+
// registering route handlers
60+
const methods = route.methods || DEFAULT_METHODS
61+
methods.forEach(method => {
62+
method = method.toLowerCase()
63+
64+
if (server[method]) {
65+
server[method](
66+
// path
67+
route.prefix + route.pathRegex,
68+
// route handler
69+
handler(route, proxy, proxyHandler),
70+
// route middlewares
71+
route.middlewares
72+
)
73+
}
74+
})
6175
})
6276

6377
return server

0 commit comments

Comments
 (0)