-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
146 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ROUTE_PREFIX=/api/v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} | ||
"trailingComma": "all", | ||
"printWidth": 120, | ||
"semi": true, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,60 @@ | ||
# koa-ts-demo | ||
|
||
Demo of Koa with TypeScript | ||
|
||
## 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 | ||
``` | ||
|
||
The development mode will auto generate `swagger.json` and `routes.ts` automatically so you don't need to run this command. | ||
This command will generate `swagger.json` file in `tsoa/swagger` folder and `routes.ts` file in `tsoa/routes` folder. Please and these two files to `.gitignore` file and **DO NOT** commit them to git. | ||
|
||
The `swagger.json` file is used by swagger UI to generate 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
export interface User { | ||
/** | ||
* @isLong ErrorMessage | ||
*/ | ||
id: number; | ||
email: string; | ||
name: string; | ||
|
Oops, something went wrong.