<img src="./docs/agua.png" alt="agua middleware framework for nodejs"/>

# Warning

This project is under development.<br>
Come back later.

## Installation

agua requires __node v7.6.0__ or higher for ES2015 and async function support

```
$ npm install agua
```

## Usage

Application structure

```
├── package.json
├── app.js (optional)
├── agent.js (optional)
├── app
|   ├── router.js
│   ├── controller
│   │   └── home.js
|   ├── extend (optional)
│   |   ├── helper.js (optional)
│   |   ├── filter.js (optional)
│   |   ├── request.js (optional)
│   |   ├── response.js (optional)
│   |   ├── context.js (optional)
│   |   ├── application.js (optional)
│   |   └── agent.js (optional)
│   ├── service (optional)
│   ├── middleware (optional)
│   │   └── response_time.js
├── config
|   ├── config.default.js
│   ├── config.prod.js
|   ├── config.test.js (optional)
|   ├── config.local.js (optional)
│   └── plugin.default.js
```

### app.js

```js
//  app.js
const Agua = require('agua').Agua;

const app = new Agua({
  basedir: path.resolve(__dirname),
});

app.listen(3000);
```

### app/router.js

```js
//  app/router.js
module.exports = (app) => {
  //  app.get(name, path, 'controller.method');
  app.get('homeIndex', '/home', 'home.index');
};
```

### app/controller/home.js

```js
//  app/controller/home.js
module.exports = (app) => {
  return class HomeController extends app.Controller {
    async index() {
      this.ctx.body = {
        message: 'helloworld',
      };
    },
  };
};
```

### app/middleware/response_time.js

```js
//  app/middleware/response_time.js
module.exports = (options, app) => {
  return async (ctx, next) => {
    let startTime = new Date();
    await next();
    let endTime = new Date();
    ctx.body = {
      ...ctx.body,
      latency: (endTime - startTime).toString(),
    };
  };
};
```

### config/config.default.js

```js
//  config/config.default.js
module.exports = {
  middleware: ['response_time'],
  'response_time': {
    enable: true,
  },
};
```

