1 | 'use strict'
|
2 |
|
3 | const log = require('./log')
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | module.exports = function(route, fileRoute, filePath, optimize, next) {
|
15 |
|
16 | log(`{cyan:Starting handler: {magenta:${ route.name } {grey:${ fileRoute }`)
|
17 |
|
18 | const processResolve = (data) => {
|
19 |
|
20 | log(`{cyan:Finished handler: {magenta:${ route.name } {grey:${ fileRoute }`)
|
21 |
|
22 | next(null, data)
|
23 |
|
24 | }
|
25 |
|
26 | const processReject = (err) => {
|
27 |
|
28 | log(`{red:Handler failed: {magenta:${ route.name } {grey:${ fileRoute }`)
|
29 |
|
30 | return next(err)
|
31 |
|
32 | }
|
33 |
|
34 | const opts = Object.assign({}, route.opts, {
|
35 | optimize: (route.opts.optimize===undefined ? optimize : route.opts.optimize)
|
36 | })
|
37 |
|
38 | route
|
39 | .handler(filePath, opts)
|
40 | .then(processResolve, processReject)
|
41 |
|
42 | } |
\ | No newline at end of file |