lark-router
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -173,2 +173,3 @@ /** | ||
this.emit('error', e, req, ...args); | ||
throw e; | ||
}); | ||
@@ -175,0 +176,0 @@ } |
{ | ||
"name": "lark-router", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "An koa route initialization and configuration module.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -97,2 +97,3 @@ lark-router | ||
``` | ||
## Async processors | ||
@@ -107,6 +108,46 @@ | ||
## Loading files and directories to generate route rules | ||
TBD... | ||
## DETAILED DOC | ||
TBD... | ||
Use `router.load(path)` to load a file or a directory. | ||
If the `path` is a file, it should export a function or an object. | ||
* function | ||
The function accepts the router as parameter. | ||
```javascript | ||
module.exports = router => { | ||
router.get('/foo/bar', (...args) => {...}); | ||
} | ||
``` | ||
Or you can return a new one if you like, but this is not recommended since you may need to re-configure this sub-router, eg. setting a adapter for this router. | ||
```javascript | ||
module.exports = () => { | ||
const router = new LarkRouter(); | ||
router.get('/foo/bar', (...args) => {...}); | ||
return router; | ||
} | ||
``` | ||
* Object | ||
If an object is exported, all the properties of the object with name in the `router.methods` should be a function and will be processed as `router.route(key, value)`. | ||
```javascript | ||
module.exports = { | ||
GET (ctx, next) => {...} | ||
POST (ctx, next) => {...} | ||
} | ||
``` | ||
_Some methods (eg. delete) are reserved words, so we recommend words capitalized or in upper case, like `GET`, `Post`_ | ||
### Loading directories with file name as param | ||
You may still want to use routes like `/:foo/:bar` in loading directories model. We have provide an adapter to do this. `router.adapter.parseFileName` will parse all file/directory names(without extend name) in the loading process. We provid a default one: | ||
``` | ||
/foo.as.param/bar.as.param.js => /:foo/:bar | ||
/foo/bar.as.asterisk.js => /foo/:bar* | ||
``` | ||
@@ -113,0 +154,0 @@ [npm-image]: https://img.shields.io/npm/v/lark-router.svg?style=flat-square |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41645
17
929
161