Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/techquery/mvkoa
Node.JS back-end framework based on Koa 2 & ECMAScript Decorator proposal
https://github.com/techquery/mvkoa
Last synced: 28 days ago
JSON representation
Node.JS back-end framework based on Koa 2 & ECMAScript Decorator proposal
- Host: GitHub
- URL: https://github.com/techquery/mvkoa
- Owner: TechQuery
- License: agpl-3.0
- Created: 2019-05-08T06:31:19.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T21:42:33.000Z (almost 2 years ago)
- Last Synced: 2024-10-05T01:36:45.302Z (about 1 month ago)
- Language: JavaScript
- Homepage: https://tech-query.me/MVKoa/
- Size: 1.1 MB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: ReadMe.md
- License: LICENSE
Awesome Lists containing this project
README
# MVKoa
Node.JS back-end framework based on [Koa 2][1] & [ECMAScript Decorator proposal][2]
[![NPM Dependency](https://david-dm.org/TechQuery/MVKoa.svg)](https://david-dm.org/TechQuery/MVKoa)
[![Build Status](https://travis-ci.com/TechQuery/MVKoa.svg?branch=master)](https://travis-ci.com/TechQuery/MVKoa)[![NPM](https://nodei.co/npm/mvkoa.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/mvkoa/)
## Basic usage
### Core logic
[`source/UserController.js`][3]
([`source/User.js`][4] is a [`Model` class][5])
```javascript
import KoaController, { GET, PATCH, POST } from 'mvkoa';import { User } from './User';
export default class UserController extends KoaController {
@GET()
listAll() {
return [];
}@PATCH('/:id')
extend(context, id, body) {
return { id, ...body };
}@POST('/', User)
create(context, body) {
return body.valueOf();
}
}
````source/index.js`
```javascript
import KoaController from 'mvkoa';
import bodyParser from 'koa-bodyparser';
import mount from 'koa-mount';import UserController from './UserController';
const app = new KoaController()
.use(async (context, next) => {
try {
await next();
} catch ({ message }) {
(context.status = 500), (context.body = message);
}
})
.use(bodyParser())
.use(mount('/users', new UserController()));app.listen(() => console.log(`Server run at ${app.address}`));
```### Installation
```shell
npm initnpm install \
mvkoa \
koa-bodyparser \
koa-mount \
data-scheme \
@babel/polyfill \
@babel/runtimenpm install \
@babel/cli \
@babel/core \
@babel/preset-env \
@babel/plugin-proposal-decorators \
@babel/plugin-transform-runtime
```### Configuration
`package.json`
```json
{
"scripts": {
"build": "babel source/ -d dist/ -s",
"start": "node dist/"
},
"engines": {
"node": "^7.6.0"
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "7.6.0"
}
}
]
],
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
"decoratorsBeforeExport": true
}
],
"@babel/plugin-transform-runtime"
]
}
}
```### Bootstrap
```shell
npm run buildnpm start
```## Advanced usage
https://tech-query.me/MVKoa/manual/
[1]: https://koajs.com/
[2]: https://github.com/tc39/proposal-decorators/tree/master/previous#readme
[3]: https://tech-query.me/MVKoa/test-file/test/source/UserController.js.html
[4]: https://tech-query.me/MVKoa/test-file/test/source/User.js.html
[5]: https://tech-query.me/DataScheme/