# Maty.js 简介

### 安装

```bash
$ npm install maty
```

{% hint style="info" %}
&#x20;Maty.js requires **node v8.0** or higher
{% endhint %}

### 功能

* Router config 简单配置即可实现接口数据的获取及页面渲染，甚至接口代理等
* Filters request/response 过滤器，可以自定义请求的处理和响应，扩展功能
* Interceptors 拦截器，可用作公共请求处理等
* ctx.forward 服务器端跳转，例如同一个路由地址，可以根据不同的参数转到不同的页面
* emplate engine 默认使用[nunjucks](https://mozilla.github.io/nunjucks/)模板引擎，支持多引擎同时使用
* Auto render 在无路由配置的情况下，自动渲染和请求路径一致的模板文件

### 工作流程示意图

![maty workflow](/files/-LPz45l3Zs7wpbekKCt-)

使用代码描述工作流程，如下：

```javascript
const app = maty();

// middleware
app.use(async (ctx, next) => {
  await next();
});

// filter
app.filter('request', async (ctx, next) => {
  // before request handler
  await next();
  // after request handler
});

// filter
app.filter('response', async (ctx, next) => {
  // before response handler
  await next();
  // after response handler
});

// middleware
app.use(async (ctx, next) => {
  await next();
});

app.listen();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tofishes.gitbook.io/maty-js/master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
