@chengaoyuan/controller

装饰器实现的Controller

Usage no npm install needed!

<script type="module">
  import chengaoyuanController from 'https://cdn.skypack.dev/@chengaoyuan/controller';
</script>

README

controller

npm version

install size

NPM Downloads

Installation

$ npm install @chengaoyuan/controller

Usage

import * as express from "express";
import { Controller, RequestMapping, RequestPath, Request, Response } from "@chengaoyuan/controller";

const app = express();
app.use(Controller);
app.listen(1234, "0.0.0.0");

@Controller("/api")
class A {
    @RequestMapping({ path: "/test", method: "POST" })
    @RequestMapping({ path: "/test", method: "GET" })
    @RequestMapping({ path: "/test", method: "DELETE" })
    @RequestMapping({ path: "/test", method: "PUT" })
    async test(a: string, b: string) {
        return "OK";
    }

    @RequestMapping("/default_get/:path")
    async default_get(@RequestPath path: string, @Request req: any, @Response res: any) {
        return "OK";
    }
}

Testing

$ npm test