1 |
|
2 | 'use strict'
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const path = require('path')
|
12 |
|
13 | const handlers = require('./handlers.js')
|
14 | const readRoutes = require('./routes/read.js')
|
15 |
|
16 | function getHandlerConfig (
|
17 | routeConfig /* : RouteConfiguration */,
|
18 | method /* : string */
|
19 | ) /* : Promise<HandlerConfiguration> */ {
|
20 | return handlers.getHandler(routeConfig.module, method)
|
21 | .then((handler) => ({
|
22 | handler,
|
23 | params: routeConfig.params || {}
|
24 | }))
|
25 | }
|
26 |
|
27 | function getRouteConfig (
|
28 | cwd /* : string */,
|
29 | route /* : string */
|
30 | ) /* : Promise<RouteConfiguration> */ {
|
31 | return readRoutes(cwd)
|
32 | .then((routeConfigs) => handlers.findRouteConfig(route, routeConfigs))
|
33 | .then((routeConfig) => {
|
34 | routeConfig.module = path.resolve(cwd, routeConfig.module)
|
35 | return routeConfig
|
36 | })
|
37 | }
|
38 |
|
39 | module.exports = {
|
40 | getHandlerConfig,
|
41 | getRouteConfig
|
42 | }
|