type-koa v0.1.7
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';
}
}
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago