Skip to content
Koa2 + Typescript = Koatty. Use Typescript's decorator implement auto injection just like SpringBoot.
TypeScript
Branch: master
Clone or download
Latest commit 80a1824 Dec 2, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode Update launch.json Dec 2, 2019
src add @scheduled Nov 29, 2019
test Test case Dec 2, 2019
.gitignore Readme Oct 18, 2019
.npmignore Readme Oct 18, 2019
LICENSE Initial commit Apr 28, 2018
README.md Update README.md Dec 2, 2019
package-lock.json Update Nov 19, 2019
package.json Update Dec 2, 2019
tsconfig.json
tslint.json Update Nov 18, 2019
yarn.lock

README.md

koatty

Koa2 + Typescript = koatty.

Use Typescript's decorator implement auto injection just like SpringBoot.

Version npmnpm Downloads

Features

  • New: @Scheduled("0 0/1 * * * ?") ✔️ 😯
  • New: @Transactional
  • New: GraphQL
  • New: SSR

Documentation

koatty_doc (In progress💪

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

koatty middleware test

4.Create a Model

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

//thinkorm
koatty middleware test

//typeorm
koatty middleware -o typeorm test

5.Define TestController

import { Controller, BaseController, Autowired, GetMaping, RequestBody, PathVariable, PostMaping, RequestMapping, RequestMethod, Valid } from "koatty";
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("/", RequestMethod.ALL)
    async default(@PathVariable("test") @Valid("notEmpty") test: string) {
        const info = await this.testService.sayHello();
        return this.ok(test, info);
    }

    @PostMaping("/test")
    test(@RequestBody() body: any) {
        return this.ok("test", body);
    }
}

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.

You can’t perform that action at this time.