UNPKG

918 BJavaScriptView Raw
1/* @flow */
2'use strict'
3
4/* ::
5import type {
6 HandlerConfiguration,
7 RouteConfiguration
8} from '../types.js'
9*/
10
11const path = require('path')
12
13const handlers = require('./handlers.js')
14const readRoutes = require('./routes/read.js')
15
16function 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
27function 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
39module.exports = {
40 getHandlerConfig,
41 getRouteConfig
42}