Nocturnal Prancing Mosquito

    koatty

    3.3.7 • Public • Published

    koatty

    Koa2 + Typescript = koatty.

    Use Typescript's decorator implement IOC and AOP.

    Version npmnpm Downloads

    Documentation

    koatty_doc_CN (In progress💪

    [koatty_doc_EN] come soon...

    Installation

    npm i -g koatty_cli

    Quick Start

    1.Create Project

    koatty new projectName
    
    cd ./projectName
    
    yarn install
    
    npm start

    2.Create a Controller

    koatty controller test
    

    3.Create a Service

    koatty service test
    

    3.Create a Middleware (Optional)

    koatty middleware test
    

    4.Create a Model(Optional)

    Supports thinkorm and typeorm. Please expand other ORM by yourself.

    //thinkorm
    koatty middleware test
    
    //typeorm
    koatty middleware -o typeorm test
    

    5.Create a DTOClass (Optional)

    koatty dto test
    

    6.Define TestController

    import { Controller, BaseController, Autowired, GetMapping, RequestBody, PathVariable, PostMapping, RequestMapping, RequestMethod, Valid } from "koatty";
    import { TestDTO } from "../model/dto/TestDTO";
    import { TestService } from "../service/TestService";
    import { App } from "../App";
    
    @Controller()
    export class IndexController extends BaseController {
        app: App;
    
        @Autowired()
        private testService: TestService;
    
        init() {
            this.cache = {};
        }
    
        @RequestMapping("/:name", RequestMethod.ALL)
        async default(@PathVariable("name") @Valid("IsNotEmpty") name: string) {
            const info = await this.testService.sayHello(name).catch((err: any) => this.fail(err.message));
            return info;
        }
    
        @PostMapping("/test")
        @Validated() //need DTOClass
        test(@RequestParam() params: TestDTO) {
            return this.ok("test", params);
        }
    }

    How to debug

    if you use vscode , edit the .vscode/launch.json , like this:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "node",
                "request": "launch",
                "name": "TS Program",
                "args": [
                    "${workspaceRoot}/src/App.ts" 
                ],
                "runtimeArgs": [
                    "--nolazy",
                    "-r",
                    "ts-node/register"
                ],
                "sourceMaps": true,
                "cwd": "${workspaceRoot}",
                "protocol": "inspector",
                "internalConsoleOptions": "neverOpen"
            }
        ]
    }
    

    Select TS Program to debug run. Try to call http://localhost:3000/ .

    Example

    Check out the quick start example.

    Install

    npm i koatty

    DownloadsWeekly Downloads

    149

    Version

    3.3.7

    License

    BSD (3-Clause)

    Unpacked Size

    1.9 MB

    Total Files

    63

    Last publish

    Collaborators

    • richenlin