https://github.com/varlinor/route-scanner
just easy to use, aimed to load route fastly and conveniently.
https://github.com/varlinor/route-scanner
Last synced: 3 months ago
JSON representation
just easy to use, aimed to load route fastly and conveniently.
- Host: GitHub
- URL: https://github.com/varlinor/route-scanner
- Owner: varlinor
- License: mit
- Created: 2020-07-23T11:27:11.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-13T09:12:59.000Z (over 2 years ago)
- Last Synced: 2024-04-24T13:36:22.295Z (about 1 year ago)
- Language: JavaScript
- Size: 131 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# route-scanner
[](https://www.npmjs.com/package/route-scanner)
[English](README.md) | [中文](docs/cn/readme_cn.md)
Recent version: v0.2.2
## Release History
See the [Change Log](docs/en/changelog.md)## Introduction
This module is a tiny tool just for scan some route file in a directory, you can use it to load masses of route files fastly and conveniently.## Quick Start
First of all, you need install `route-scanner` to your project:
```
npm i route-scanner --save
```then, import the module and initialize it in your `app.js` just like below:
```
const routeScanner = require('route-scanner');
......routeScanner(app,{
debug:false,
framework:'express', // express or koa2
routerPath: path.join(__dirname, 'routes'),
prefix:'std', // modifier
replacePaths:[{
from:'/index',
to:'/'
}],
extraMaps:[{
rootPath:path.join(__dirname, '/core/base-routes'),
fileMaps:[{
url:'/admin',
file:'admin.js'
}]
}]
});
......
// other express codes to use middleware
module.exports=app;
```after that, you can create any router file in directory `/routes/`, and don't write `use` sentence in `app.js`.
## Configuration
### debug
You can set `debug:true` to open scan logs print.
```
{
debug:true
}
```### framework
You can set `express` or `koa2` to specify the framework, if empty ,
`express` is default.
```
{
framework:'express'
}
```### routerPath
Specify the root for those route files. It's an absolutly path, so you can input like this:
```
{
routerPath: path.join(__dirname, 'routes'),
}
```### prefix
Specify the prefix of the url, if you fill a string, then your root url turned to `http://localhost:3000/string`, and also, the empty value is possible.
```
{
prefix:'yourProjectName' // url is http://localhost:3000/yourProjectName
}
// or
{
prefix:'' // url is http://localhost:3000
}
```### replacePaths
If you want to change a file name to an other url, you can use this option:
```
{
replacePaths:[{
from:'/index',
to:'/mgr/index'
}],
// enter http://localhost:3000/mgr/index will directed to index.js
}
```
then, the route file `/routes/index.js` will be mapped to `/mgr/index`,
so the full url is `http://localhost:3000/mgr/index`, when you enter
this url , it will be directed to `index.js`### extraMaps
Specify another path to load other route files, you can use it like below:
```
{
extraMaps:[{
rootPath:path.join(__dirname, '/another-routes-path'),
fileMaps:[{
url:'/admin',
file:'admin.js'
},{
url:'/service',
file:'/subdir/service.js'
}]
}]
}
```Just support a way to mapping file and url, you can use it easily
## License
Copyright (c) 2020 George under the [MIT License](LICENSE)