Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/shipengqi/sactive-web

:rocket: A dependency injection web framework for Node.js.
https://github.com/shipengqi/sactive-web

dependency-injection koa koa-router koa2 webframework

Last synced: about 11 hours ago
JSON representation

:rocket: A dependency injection web framework for Node.js.

Awesome Lists containing this project

README

        


SActive Web


:rocket: A dependency injection web framework for Node.js.



Build Status


Build Status


License


NPM version


NPM Download


License

## Installation
```bash
npm install sactive-web
```

> **Note that 3.x.x is not compatible with 2.x.x and below** !!!

## Features

- Dependency injection.
- Router, grouping routes, based on [koa-router](https://github.com/alexmingoia/koa-router).
- Interceptors.
- Based on [Koa2](https://github.com/koajs/koa).

## Example

```javascript
const App = require('..');

const app = new App();
app.bindAny('name', 'pooky');

app.use(($ctx, $name, $next) => {
$ctx.testname1 = $name;
$next();
});

app.group('v1')
.get('/users/:name', ($ctx, $next, $name) => {
$ctx.body = {'name': $ctx.params.name, 'testname1': $ctx.testname1, 'testname2': $name};
});
app.group('v2/')
.get('/users/:name', ($name, $ctx, $next) => {
$ctx.response.body = {'name': $ctx.params.name, 'testname1': $ctx.testname1, 'testname2': $name};
});
app.group('/v3/')
.get('/users/:name', ($ctx, $name, $next) => {
$ctx.body = {'name': $ctx.params.name, 'testname1': $ctx.testname1, 'testname2': $name};
});

app.listen(8080);
```

## Documentation
- [Usage Guide](./docs/README.md)
- [API Reference](./docs/api.md)

## Babel setup
If you're not using `node v7.6+`, you can refer [koa installation](https://koajs.com/#introduction).

## Debugging
sactive-web along with many of the libraries it's built with support the __DEBUG__ environment variable from [debug](https://github.com/visionmedia/debug) which provides simple conditional logging.

For example
to see all sactive-web debugging information just pass `DEBUG=active:*` and upon boot you'll see the list of middleware used, among other things.
```bash
active:di bind class: injector, singleton: true +0ms
active:di bind any: age, singleton: true +1ms
active:application use - +0ms
active:application use - +0ms
active:application register get /users/:name +1ms
active:application register get /users/ +0ms
active:application use - +0ms
active:di bind any: address, singleton: true +3ms
active:di bind function: getAddress, singleton: true +1ms
active:application listen +1ms
```

## Tests
Install the dependencies, then run `npm test`:
``` bash
npm install
npm test

# coverage
npm run test:cov
```

## TODO
- Benchmark test