1 | 'use strict'
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | module.exports = function(routes, srcPath, opts, next) {
|
13 |
|
14 |
|
15 | const validate = require('./validate')
|
16 | const rewrite = require('./rewrite')
|
17 | const redirect = require('./redirect')
|
18 | const deliver = require('./deliver')
|
19 |
|
20 |
|
21 |
|
22 | if (next==null) next = opts
|
23 |
|
24 | try {
|
25 |
|
26 | next = validate.next(next)
|
27 | routes = routes.map(validate.route)
|
28 | srcPath = validate.path(srcPath)
|
29 | opts = validate.opts(opts)
|
30 |
|
31 | } catch (err) {
|
32 |
|
33 | return next(err)
|
34 |
|
35 | }
|
36 |
|
37 |
|
38 | process.on('unhandledRejection', next)
|
39 |
|
40 | const _rewrite = rewrite(routes, srcPath)
|
41 | const _redirect = redirect()
|
42 |
|
43 | deliver(srcPath, _rewrite, _redirect, opts, next)
|
44 |
|
45 | } |
\ | No newline at end of file |