Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chicunic/koa-ts-demo
Demo of Koa with TypeScript (tsoa & swagger UI)
https://github.com/chicunic/koa-ts-demo
koa swagger tsoa typescript
Last synced: 16 days ago
JSON representation
Demo of Koa with TypeScript (tsoa & swagger UI)
- Host: GitHub
- URL: https://github.com/chicunic/koa-ts-demo
- Owner: chicunic
- License: mit
- Created: 2023-08-28T01:50:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-30T06:04:18.000Z (11 months ago)
- Last Synced: 2024-10-16T19:12:00.504Z (2 months ago)
- Topics: koa, swagger, tsoa, typescript
- Language: TypeScript
- Homepage:
- Size: 272 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-ts-demo
Demo of Koa with TypeScript (tsoa & swagger UI)
## Usage
Start with development mode:
```bash
pnpm run start:dev
```Start with production mode:
```bash
pnpm run start:prod
```Format code:
```bash
pnpm run format
```Lint code:
```bash
pnpm run lint
```Build code:
```bash
pnpm run build
```## Router
How to add a new router (e.g. `/users`):
1. Create a new file `usersController.ts` in `src/users/` folder. (e.g.`src/users/UsersController.ts`)
2. Add a new router in `usersController.ts` file with `@Route('users')` decorator.
3. Add a new class `UsersController` in `usesrsController` folder extends `Controller` class from `tsoa` package.
4. Use `@Get()` decorator to add a new GET method or use `@Post()` decorator to add a new POST method, etc.## Swagger
The swagger.json file is generated by `tsoa` package. The swagger UI is served by `koa2-swagger-ui` package.
How to generate swagger.json:
```bash
pnpm run build:swagger
```This command will generate `swagger.json` file in `dist/static` folder and `routes.ts` file in `src/routes` folder. Please and these two files to `.gitignore` file and **DO NOT** commit them to git.
The development mode will generate `swagger.json` and `routes.ts` automatically so you don't need to run this command.
The `swagger.json` file is used by swagger UI to display the swagger UI page. The `routes.ts` file is used by `@koa/router` in Koa.
If you want to show the swagger UI page, please visit `http://localhost:8080/api/v1` in your browser.