innots
Core ecom rnd lib
Last updated 8 days ago by khromushkin .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install innots 
SYNC missed versions from official npm registry.

innots is a wrapper around koa framework and some popular koa middlewares for quick app init and bootstrap.

Build Status

Overview

First of all module is designed to use with typescript and it's async await implementation but you can also use it with plain javascript.

import {InnotsApp, Context} from 'innots';

const app = new InnotsApp({
    port: 9080
});

app.route('post', '/test', async (ctx: Context, next: () => any): Promise<void> => {
   ctx.body = 1;
   await next();
});

app.bootstrap().then(() => {
    console.log('Server started');
});

You can also define validation middleware in route method (validation is powered by joi library):

app.route(
    'get',
    '/foo,
    ((joi) => {
        return joi.object().keys({
            testField: joi.string().trim().email().required(),
            testQueryField: joi.number().integer()
        });
    }),
    async (ctx: Context, next: () => any): Promise<void> => {
       // you can access your data by ctx.validatedData (.camelCase or .originalCase) parameter
       await next();
    })
);

Usage

InnotsApp class

new InnotsApp(config: IAppConfig, router?: Router, customMiddlewares?: IAppMiddlewares)

Constructs new http server (powered by koa framework) with pre-defined built in router and middlewares.

config: IAppConfig

An object for configuring built in middlewares.

{
    host?: string; // listening host, e.g. 'localhost'
    port: number; // listening port
    jwt?: { // config for jwt middleware (jwt middleware is enabled if config exists)
        secret: string; // jwt secret 
        publicPath: string; // regexp for public paths (not protected by jwt)
        prefix?: string; // prefix before token in auth header (e.g JWT in "JWT <token>", or "Bearer" in "Bearer <token>")
    };
    cors?: { // CORS is enabled by default, you can edit it by providing this config param
        enabled: boolean; // enable/disable CORS
        origin: string; // Access-Control-Allow-Origin header
        credentials: string; // Access-Control-Allow-Credentials header
    };
    userAgent?: boolean; // Enable or disable userAgent processing middleware
    enableLogMiddleware?: boolean; // Enable or disable request info logging middleware
}

router?: Router

An instance of koa-router (you can use it if you don't want to use built in router)

customMiddlewares: IAppMiddlewares

An object with your own custom implementations if middlewares (if you don't want to use built in middlewares):

{
    bodyParser?: Middleware; // bodyParser middleware - defaults to koa-bodyparser
    log?: Middleware;
    error?: Middleware; 
    jwt?: Middleware;
    cors?: Middleware;
    userAgent?: Middleware;
    success?: Middleware;
}

app.route(method: string, url: string, joiSchemaGenerator: TJoiSchemaGenerator, ...actions: IMiddleware[]): void

app.route(method: string, url: string, ...actions: IMiddleware[]): void

Defines middleware for processing request.

app.route(
    'get',
    '/foo,
    async (ctx: Context, next: () => any): Promise<void> => {
       ctx.body = true
       await next();
    })
);

You can also make validation middleware here:

app.route(
    'get',
    '/foo,
    ((joi) => {
        return joi.object().keys({
            testField: joi.string().trim().email().required(),
            testQueryField: joi.number().integer()
        });
    }),
    async (ctx: Context, next: () => any): Promise<void> => {
       // you can access your data by ctx.validatedData parameter
       await next();
    })
);

app.bootstrap(): Promise<void>

Starts your app with defined routes and middlewares.

Current Tags

  • 2.0.0                                ...           latest (8 days ago)

102 Versions

  • 2.0.0                                ...           8 days ago
  • 1.5.10                                ...           2 months ago
  • 1.5.9                                ...           2 months ago
  • 1.5.8                                ...           3 months ago
  • 1.5.7                                ...           3 months ago
  • 1.5.6                                ...           3 months ago
  • 1.5.5                                ...           3 months ago
  • 1.5.4                                ...           3 months ago
  • 1.5.3                                ...           3 months ago
  • 1.5.2                                ...           3 months ago
  • 1.5.1                                ...           3 months ago
  • 1.5.0                                ...           3 months ago
  • 1.4.1                                ...           3 months ago
  • 1.4.0                                ...           3 months ago
  • 1.3.1                                ...           3 months ago
  • 1.3.0                                ...           3 months ago
  • 1.2.7                                ...           4 months ago
  • 1.2.6                                ...           4 months ago
  • 1.2.5                                ...           7 months ago
  • 1.2.4                                ...           7 months ago
  • 1.2.3                                ...           9 months ago
  • 1.2.2                                ...           9 months ago
  • 1.2.1                                ...           a year ago
  • 1.2.0                                ...           a year ago
  • 1.1.14                                ...           a year ago
  • 1.1.13                                ...           a year ago
  • 1.1.12                                ...           a year ago
  • 1.1.11                                ...           a year ago
  • 1.1.10                                ...           a year ago
  • 1.1.9                                ...           a year ago
  • 1.1.8                                ...           a year ago
  • 1.1.7                                ...           a year ago
  • 1.1.6                                ...           a year ago
  • 1.1.5                                ...           a year ago
  • 1.1.4                                ...           a year ago
  • 1.1.3                                ...           a year ago
  • 1.1.2                                ...           a year ago
  • 1.1.1                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.28                                ...           a year ago
  • 1.0.27                                ...           a year ago
  • 1.0.25                                ...           a year ago
  • 1.0.24                                ...           2 years ago
  • 1.0.23                                ...           2 years ago
  • 1.0.22                                ...           2 years ago
  • 1.0.21                                ...           2 years ago
  • 1.0.20                                ...           2 years ago
  • 1.0.19                                ...           2 years ago
  • 1.0.18                                ...           2 years ago
  • 1.0.17                                ...           2 years ago
  • 1.0.16                                ...           2 years ago
  • 1.0.15                                ...           2 years ago
  • 1.0.14                                ...           2 years ago
  • 1.0.13                                ...           2 years ago
  • 1.0.12                                ...           2 years ago
  • 1.0.11                                ...           2 years ago
  • 1.0.10                                ...           2 years ago
  • 1.0.9                                ...           2 years ago
  • 1.0.8                                ...           2 years ago
  • 1.0.7                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.0.38                                ...           2 years ago
  • 0.0.37                                ...           2 years ago
  • 0.0.35                                ...           2 years ago
  • 0.0.34                                ...           2 years ago
  • 0.0.33                                ...           2 years ago
  • 0.0.32                                ...           2 years ago
  • 0.0.30                                ...           2 years ago
  • 0.0.31                                ...           2 years ago
  • 0.0.29                                ...           2 years ago
  • 0.0.28                                ...           2 years ago
  • 0.0.27                                ...           2 years ago
  • 0.0.26                                ...           2 years ago
  • 0.0.25                                ...           2 years ago
  • 0.0.24                                ...           2 years ago
  • 0.0.22                                ...           2 years ago
  • 0.0.21                                ...           2 years ago
  • 0.0.20                                ...           2 years ago
  • 0.0.19                                ...           2 years ago
  • 0.0.18                                ...           2 years ago
  • 0.0.17                                ...           3 years ago
  • 0.0.16                                ...           3 years ago
  • 0.0.15                                ...           3 years ago
  • 0.0.14                                ...           3 years ago
  • 0.0.13                                ...           3 years ago
  • 0.0.12                                ...           3 years ago
  • 0.0.11                                ...           3 years ago
  • 0.0.10                                ...           3 years ago
  • 0.0.9                                ...           3 years ago
  • 0.0.8                                ...           3 years ago
  • 0.0.7                                ...           3 years ago
  • 0.0.6                                ...           3 years ago
  • 0.0.4                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Downloads
Today 1
This Week 1
This Month 344
Last Day 0
Last Week 241
Last Month 2
Dependencies (29)
Dev Dependencies (10)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |