koa-rtapi
Advanced tools
Comparing version 1.1.4 to 1.1.6
68
index.js
'use strict'; | ||
// 返回错误 | ||
const outError = (ctx, result, code) => { | ||
ctx.body = result; | ||
ctx.status = code; | ||
}; | ||
// 获取路由配置 | ||
const getRouterOpt = (path, dir) => { | ||
const arr = path.substr(1).split('/'); | ||
const last = arr.length - 1; | ||
return { | ||
aPath: last < 2 ? null : `../..${dir}${arr.slice(1, last).join('/')}.api.js`, | ||
aName: '$' + (arr[last] || 'index') | ||
} | ||
}; | ||
module.exports = map => { | ||
return async (ctx, next) => { | ||
const path = ctx.path; | ||
const router = map.find(n => path.indexOf(n.path) === 0); | ||
if (router !== undefined) { | ||
// 解析 | ||
const { aPath, aName } = getRouterOpt(path, router.dir); | ||
if (aPath === null) { | ||
return outError(ctx, `未能解析网址|${path}`, 404); | ||
} | ||
// 控制器 | ||
let api; | ||
try { | ||
const Api = require(aPath); | ||
api = new Api(ctx); | ||
} catch (e) { | ||
return outError(ctx, `控制器错误|${e.message}|${e.stack}`, 500); | ||
} | ||
// 方法 | ||
const method = api[aName]; | ||
if (method === undefined) { | ||
return outError(ctx, `没有找到方法|${aName}`, 404); | ||
} | ||
// 执行API | ||
const body = ctx.method === 'GET' ? ctx.query : ctx.request.body; | ||
try { | ||
api.ctx = ctx; | ||
ctx.body = await method.call(api, body); | ||
} catch (e) { | ||
return outError(ctx, `执行时出错|${e.message}|${e.stack}`, 500); | ||
} | ||
} | ||
await next(); | ||
}; | ||
}; | ||
module.exports = { | ||
api: require('./lib/api'), | ||
env: require('./lib/env'), | ||
coder: require('./lib/coder'), | ||
ApiBase: require('./lib/api-kit/apiBase'), | ||
ManageBase:require('./lib/api-kit/manageBase'), | ||
Access: require('./lib/sql-kit/access'), | ||
Select: require('./lib/sql-kit/select') | ||
} |
{ | ||
"name": "koa-rtapi", | ||
"version": "1.1.4", | ||
"version": "1.1.6", | ||
"description": "koa api in rtworld company", | ||
"main": "index.js", | ||
"bin": { | ||
"koa-rtapi-init": "./_bin_init.js" | ||
"koa-rtapi-init": "./init_code.js" | ||
}, | ||
@@ -18,4 +18,6 @@ "scripts": { | ||
"koa2-cors": "^2.0.6", | ||
"koa-static": "^5.0.0" | ||
"koa-static": "^5.0.0", | ||
"request": "^2.88.0", | ||
"mysql": "^2.17.1" | ||
} | ||
} |
# koa-rtapi | ||
**简介** | ||
## 简介 | ||
- 创建一个http服务器 `(koa2)` | ||
- 简化的基于文件的api路由 | ||
- 支持 `request.body(koa-bodyparser)`,`跨域(koa2-cors)`,`静态服务(koa-static)` | ||
- 集成了tkui(填坑UI)和前后台生成工具 | ||
- 集成了代码在线编辑工具 | ||
- power by 村长扫大街 | ||
**初始化** | ||
## 初始化 | ||
``` | ||
npm init -y && npm i koa-rtapi && npx koa-rtapi-init && --start-- | ||
npm init -y && npm i koa-rtapi && npx koa-rtapi-init && node index | ||
``` | ||
**更新** | ||
## 更新 | ||
``` | ||
@@ -17,3 +20,3 @@ npm update koa-rtapi | ||
**启动** | ||
## 启动 | ||
``` | ||
@@ -23,5 +26,8 @@ node index | ||
**文件说明** | ||
## 文件说明 | ||
- index.js 启动和配置 | ||
- api/ 放api文件 | ||
- api/ api文件 | ||
- coder.api.js: 代码生成api | ||
- demo.api.js: 范例api | ||
- coder/ 代码生成模板 | ||
- www/ 放静态文件 |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
510832
61
13057
31
6
2
10
2
+ Addedmysql@^2.17.1
+ Addedrequest@^2.88.0
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.0(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbignumber.js@9.0.0(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.21.0.3(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmysql@2.18.1(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedpsl@1.9.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedreadable-stream@2.3.7(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsqlstring@2.3.1(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)