Coder Social home page Coder Social logo

shipengqi / sactive-web Goto Github PK

View Code? Open in Web Editor NEW
139.0 2.0 0.0 1.64 MB

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

Home Page: https://shipengqi.github.io/sactive-web

License: MIT License

JavaScript 99.63% Shell 0.37%
koa2 dependency-injection webframework koa-router koa

sactive-web's Introduction

SActive Web

๐Ÿš€ A dependency injection web framework for Node.js.

Build Status Build Status License NPM version NPM Download License

Installation

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.
  • Interceptors.
  • Based on Koa2.

Example

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

Babel setup

If you're not using node v7.6+, you can refer koa installation.

Debugging

sactive-web along with many of the libraries it's built with support the DEBUG environment variable from 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.

  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:

npm install
npm test

# coverage
npm run test:cov

TODO

  • Benchmark test

sactive-web's People

Contributors

dependabot[bot] avatar gdx-pooky avatar shipengqi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.