# routs

> 基于JSON的路由配置方案

Latest version **1.0.6** (published 2018-06-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install routs
pnpm add routs
yarn add routs
bun add routs
```

Provides the commands `ng1`, `routs-es6`, `routs-ng1`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2018-06-09 |
| First published | 2017-05-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 95.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | sankooc |
| Maintainers | sankooc |

## Links

- npm: https://www.npmjs.com/package/routs
- Repository: https://github.com/sankooc/routs
- Homepage: https://github.com/sankooc/routs#readme
- Issues: https://github.com/sankooc/routs/issues
- npm.io page: https://npm.io/package/routs

## Dependencies (7)

- [co](https://npm.io/package/co.md) ^4.6.0
- [chalk](https://npm.io/package/chalk.md) ^2.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [express](https://npm.io/package/express.md) ^4.15.3
- [escodegen](https://npm.io/package/escodegen.md) ^1.8.1
- [validatez](https://npm.io/package/validatez.md) ^1.2.0
- [eslint-config-airbnb](https://npm.io/package/eslint-config-airbnb.md) ^12.0.0

## Recent versions

- 1.0.6 (latest) — 2018-06-09
- 1.0.5 — 2017-09-07
- 1.0.4 — 2017-08-14
- 1.0.3 — 2017-06-01
- 1.0.2 — 2017-05-31
- 1.0.1 — 2017-05-26
- 1.0.0 — 2017-05-08

## README

# routs

基于JSON的路由配置方案

## 目标

* 直观的路由配置
* 方便测试
* 自动生成前端服务模板(angular, redux ...) [WIP]

![mini](pic.png)

## 安装

` npm i routs `

## 配置

简单示例:  [demo](example)

yoeman scaffold: [asn](https://github.com/sankooc/generator-asn)


### 开始

```
const express = require('express');
const mroute = require('routs');
const app = express();

mroute.express(app, routerConfig, {
  routes,
  filters,
  validators,
  suffixs,
});
// routerConfig 路由配置文件
// routes: routing
// filters: 过滤器
// validators: 请求验证
// suffixs: 响应封装

```

### 路由配置

#### router config

```

{
  path: '/akb',
  routes: [], //routing config
  filters: [], // filters
}

```

#### routing config

```

{
  path: '/excel',
  match: 'print', 
  filters: ['auth'], //optional
  validate: 'vdata', //optional 
  method: 'post', //optional default is get 
  ext: 'excel', //optional default is json
  alias: 'download', // optional template service name
  desc: 'download excel file' // optional template service comments
}

```

| field     | value  | optional | routing/router |      desc       |   
|-----------|--------|----------|----------------|-----------------|
| path      | string |   false  |   true/true    |   routing path  |
| filters   | string |   true   |   true/true    | route filtering |
| routes    | array  |   false  |  false/true    |   sub routings  |
| match     | string |   false  |  true/false    | routing handle  |
| method    | string |   true   |  true/false    | routing method (post, put, get, delete, default is get) |
| ext       | string |   true   |  true/false    | response format |
| alias     | string |   true   |  true/false    | routing alias   |
| desc      | string |   true   |  true/false    | routing desc    |

生成模板服务时alias必须设置


### 请求验证

请求验证格式通过[validatez](https://github.com/sankooc/validatez)实现

### 过滤器

提供request,response. 返回结果通过co模块处理 

### routing

提供request,response. 返回结果通过co模块处理 


## 生成模板代码

### angular1 service

` ng1 [config file] [folder] `



## 工具方法

express中间件集成转换

```

const mroute = require('routs');

const mid = (req, res, next) => { ... } //express midware
exports.mid = mroute.swap(mid); // convert to routs-filter

```

## change log

### 1.03
 - 生成模板代码时alias字段成为可选项

---
_Source: https://npm.io/package/routs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
