0.1.7 • Published 3 years ago

type-koa v0.1.7

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

TypeKoa is a new web framework build on top of Koa and heavily inspired by EggJs. This project aims to add more TypeScript's feature to Koa like decorators for url routing.

Also, the start up time of EggJs is a bit slow as it launch process as a cluster. Forking process and generating those typing file is too slow for running a test cases. Therefore I am trying to write a new web framework for optimising this part.

You may launch your application by using this framework to GCP function too.

Project Design

Project Structure

    showcase
    ├── app
    │   ├── controller
    │   │   └── home.ts
    │   ├── middleware
    │   │   └── checkData.ts
    │   ├── index.ts
    ├── test
    │   └── **/*.test.ts
    ├── README.md
    ├── package.json
    ├── tsconfig.json

Init

import { TypeKoa }         from 'type-koa';
import ActionController            from "./controller/ActionController";
import MiddlewareController        from "./controller/MiddlewareController";

let port: number = 80;
let host: string = process.env.HTTP_HOST || '';



let typeKoa = new TypeKoa();
typeKoa.bootstrapControllers({
    controllerList: [
      ActionController,
      MiddlewareController
    ],
    middlewareList: [
      addHeaderFromMiddleware
    ]
  });

typeKoa.app.listen(port, host);
const app = typeKoa.app.callback();

console.log(`Server started at: http://${host}:${port}`);
export { app }

Controller + Router

get / post / delete / batch method can be define directly inside controller for Koa router.

    import { Controller, Delete, Get, Patch, Post, Put } from '../../src';
    import { Context } from "koa";
    
    @Controller('/action')
    export class ActionController {
      @Get('/')
      async getRoute(ctx: Context) {
        ctx.body = 'home';
      }
    
      @Post('/')
      async postRoute(ctx: Context) {
        ctx.body = 'post home';
      }
    }
0.1.7

3 years ago

0.1.6

3 years ago

0.0.24

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.5

3 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.12

4 years ago

0.0.13

4 years ago

0.0.14

4 years ago

0.0.15

4 years ago

0.0.16

4 years ago

0.0.17

4 years ago

0.0.18

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago