Socket
Socket
Sign inDemoInstall

koa-rtapi

Package Overview
Dependencies
120
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.4 to 1.1.6

code/--start--.bat

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/ 放静态文件
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc