Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pdsuwwz/koa-server-boilerplate
☂️ A boilerplate for Koa Server with Typescript, Babel, and Rollup
https://github.com/pdsuwwz/koa-server-boilerplate
babel boilerplate eslint hmr-support koa-server koa2 nodemon pm2 rollup typescript
Last synced: 20 days ago
JSON representation
☂️ A boilerplate for Koa Server with Typescript, Babel, and Rollup
- Host: GitHub
- URL: https://github.com/pdsuwwz/koa-server-boilerplate
- Owner: pdsuwwz
- License: mit
- Created: 2021-12-16T05:13:56.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-15T18:13:42.000Z (25 days ago)
- Last Synced: 2024-12-15T19:24:46.895Z (25 days ago)
- Topics: babel, boilerplate, eslint, hmr-support, koa-server, koa2, nodemon, pm2, rollup, typescript
- Language: TypeScript
- Homepage:
- Size: 315 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-server-boilerplate
☂️ A boilerplate for Koa Server with Typescript, Babel, and Rollup## Prerequisites
Please make sure that [Node.js](https://nodejs.org/) (>= 10.18.1) is installed on your operating system.
## Feature
🌟 Separation Services logic and Controllers.
🍓 The Friendly practice for Koa project.
🌲 Configured routing.
☃ `Eslint` configuration.
⚡ Fast build with `Rollup`.
🔥 HMR.
## Project structure
```
├── src
│ ├── controllers/ --- Server controllers
│ ├── services/ --- Server services
│ ├── config.ts --- About Environments variable
│ ├── main.ts --- Entry file
│ └── routes.ts --- Configs for routing controllers
```## Installation
```bash
pnpm install
```## Running Development
```bash
pnpm dev
```## Running Production
The project has built-in a `pm2`, when the `build` is completed, you can running the `pnpm start`, which will automatically manage the process by `pm2`.
Run `pnpm build` to build:
```bash
pnpm build
```All done! Now run this in your terminal:
```bash
pnpm start
```## Simple API
> `/api` is the prefix for all routes.
* `GET /api`
Health check.
```bash
curl --location --request GET \
'http://localhost:5000/api'
```* `GET /api/get_userinfo`
Get User Info.
```bash
curl --location --request GET \
'http://localhost:5000/api/get_userinfo?userId=1234567'
```* `POST /api/gen_image`
Generate a image to response.
```bash
curl --location --request POST 'http://localhost:5000/api/gen_image' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'url=http://www.google.com' --output test-image.png
```## Routing
In order to make the routing information more readable and transparent, the form of configuration is adopted here.
You can create an `array` and then write the routing meta information into the `array`, and reuse it in the `src/routes.ts`
```ts
const routes: Array = [
{
path: '/',
method: 'get',
action: HomeController.hello
},
// here...
]
```# License
[MIT](LICENSE)