Simple koa decorators
install: npm install koa-ts-decorators
Decorators:
- @Controller
- @Middleware
- @Get
- @Post
- @Put
- @Delete
Example
Basic:
;; const config: IKoaDConfig = listening: "*:3001" enable: true prefix: "/" proxy: false subdomain_offset: 2 proxy_header: "X-Forwarded-For" ips_count: 0 @ // path /healthcheck@ // path / { //console.log(app_id); //console.log(controller_name); //console.log(prefix); } @ { ctxstateflag = true; ; } @ // route GET / @ // route GET /hello @ // route POST / @ // route POST /hello : void console; if ctxstateflag === true ctxbody = "OK"; ctxstatus = 200; else ctxbody = "Error"; ctxstatus = 500; @ implements IMiddleware { //console.log(app_id); //console.log(middleware_name); } : unknown console; return ; const app = config; // create koad app (extended koa app) // additional parameters and methodsconsole;console;console;console; app;app; app;
2 application:
;; const config: IKoaDConfig = listening: "*:3001" // listing host and port enable: true // enable/disable application prefix: "/" // global prefix proxy: false // koa app.proxy subdomain_offset: 2 // koa app.subdomainOffset proxy_header: "X-Forwarded-For" // koa app.proxyHeader ips_count: 0 // koa app.ipsCount //keys?: string[] // koa app.keys //env?: "development" // koa app.env @ // second app, path /healthcheck@ // second app, path /@ // default app, path /healthcheck@ // default app, path / @ @ { ctxstateflag = true; ; } @ // route GET / @ // route GET /hello @ @ : void console; if ctxstateflag === true ctxbody = "OK"; ctxstatus = 200; else ctxbody = "Error"; ctxstatus = 500; @@ implements IMiddleware : unknown console; return ; const app1 = config; // create koad app1const app2 = config "second"; // create koad app2 app1; app2;