npm init -y
替换所需要的依赖,以及脚本路径
// scripts
"scripts": {
"start": "ts-node-dev ./src/index.ts -P tsconfig.json --no-cache",
"build": "tsc -P tsconfig.json && node ./dist/index.js",
"tslint": "tslint --fix -p tsconfig.json"
},
// dep
"devDependencies": {
"@types/node": "^14.14.12",
"ts-node": "^9.1.1",
"ts-node-dev": "^1.0.0",
"tslint": "^6.1.3",
"typescript": "^4.1.3"
},
"dependencies": {
"koa": "^2.13.0",
"koa-body": "^4.2.0",
"koa-static": "^5.0.0",
"koa-xtime": "^1.0.0",
"mysql2": "^2.2.5",
"reflect-metadata": "^0.1.13",
"sequelize": "^6.3.5",
"sequelize-typescript": "^1.1.0"
}
创建src/routes/user.ts,添加基础的配置
import * as Koa from 'koa'
import {
get, post ,middlewares} from '../framework/decors'
const users = [{
name: 'xiaozhang',
age: 18
}]
@middlewares