Socket
Socket
Sign inDemoInstall

koa-rtapi

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-rtapi - npm Package Compare versions

Comparing version 1.2.3 to 1.2.4

16

code-pure/index.js

@@ -22,4 +22,16 @@ 'use strict'

mysql: {
db1: { host: '192.168.1.191', port: '3306', user: 'rtworld', password: 'rtworld123456', database: 'node_tester' }
db1: { host: '192.168.1.191', port: '3306', user: 'rtworld', password: 'rtworld123456', database: 'rtworld_dew' }
}
},
// 日志
log: function (k1, k2, k3) {
const t = this;
if (typeof k1 === 'object') {
console.log(k1);
} else {
let r = `--- ${t.rid} : ${new Date().toLocaleString()} [${k1}] ${k2}`;
if (k3 !== undefined) { r += ` | ${util.inspect(k3)}`; }
console.log(r);
}
}

@@ -30,3 +42,3 @@ };

/** 启动服务 */
kapp.use(rtapi.env(cfg.env)) // 添加配置
kapp.use(rtapi.env(cfg.env, cfg.log)) // 添加配置
.use(require('koa-bodyparser')()) // 支持post-body

@@ -33,0 +45,0 @@ .use(rtapi.api(cfg.apis)) // 开启rtapi

@@ -13,2 +13,3 @@ /*<%#

this._client = ctx.env.mysql['db1'];
this._client.ctx = ctx;
}

@@ -15,0 +16,0 @@

@@ -5,2 +5,3 @@ 'use strict'

const rtapi = require('koa-rtapi');
const util = require('util');
const kapp = new Koa();

@@ -29,4 +30,16 @@

mysql: {
db1: { host: '192.168.1.191', port: '3306', user: 'rtworld', password: 'rtworld123456', database: 'node_tester' }
db1: { host: '192.168.1.191', port: '3306', user: 'rtworld', password: 'rtworld123456', database: 'rtworld_dew' }
}
},
// 日志
log: function (k1, k2, k3) {
const t = this;
if (typeof k1 === 'object') {
console.log(k1);
} else {
let r = `--- ${t.rid} : ${new Date().toLocaleString()} [${k1}] ${k2}`;
if (k3 !== undefined) { r += ` | ${util.inspect(k3)}`; }
console.log(r);
}
}

@@ -37,3 +50,3 @@ };

/** 启动服务 */
kapp.use(rtapi.env(cfg.env)) // 添加配置
kapp.use(rtapi.env(cfg.env, cfg.log)) // 添加配置
.use(require('koa2-cors')()) // 开启跨域

@@ -40,0 +53,0 @@ .use(require('koa-static')(cfg.stc.root, cfg.stc.opts)) // 静态支持

2

init_code.js

@@ -27,3 +27,3 @@ #!/usr/bin/env node

const [node, path, ...argv] = process.argv;
const [, , ...argv] = process.argv;
const dir = __dirname + '/code' + (argv[0] || '');

@@ -30,0 +30,0 @@ copyDir(dir, __dirname + '/../..');

@@ -19,6 +19,6 @@

* @param val 输入的变量
* @param para 验证参数(数字的默认值/正则表达式/验证方法)
* @param para 验证参数(数字的默认值/正则表达式/验证方法/枚举数组)
* @param failMsg 错误信息
*/
value(val: any, para?: number | RegExp | any, failMsg?: string): any;
value(val: any, para?: number | RegExp | Array | Function, failMsg?: string): any;

@@ -25,0 +25,0 @@

@@ -37,7 +37,11 @@

default:
// 验证枚举
if (para instanceof Array) {
if (para.indexOf(val) > -1) { return val; }
}
// 正则表达式验证
if (para instanceof RegExp) {
else if (para instanceof RegExp) {
if (val === undefined) { val = ''; }
if (para.test(val)) { return val; }
break;
}

@@ -44,0 +48,0 @@ }

@@ -96,3 +96,3 @@

await t.access.buildOuter(r);
return t.output(r);

@@ -99,0 +99,0 @@ }

// 输出Koa的组件
module.exports = env => {
module.exports = (env, log) => {
// 输出配置文件
console.log(JSON.stringify(env, null, 2));
return async (ctx, next) => {
// 加入环境配置
ctx.env = env;
// 加入访问id
ctx.rid = ctx.app.rid = (ctx.app.rid || 0) + 1;
// 加入日志
ctx.rlog = log || function () { };
// 入口日志
ctx.rlog(ctx.method, ctx.url);
await next();
// 出口日志
ctx.rlog(ctx.status, ctx.length);
if (ctx.status >= 500) { ctx.rlog(ctx.body); }
}
}

@@ -44,5 +44,2 @@ const mysql = require('mysql');

// 输出到控制台
console.log(sql, paras);
// 将参数转为数组

@@ -53,4 +50,7 @@ if (paras != undefined && !Array.isArray(paras)) {

const promise = new Promise((res, rej) => {
// 日志
t.db_cfg.ctx.rlog('sql', sql, paras);
return new Promise((res, rej) => {
var connection = mysql.createConnection(t.db_cfg);

@@ -67,4 +67,2 @@ connection.connect();

});
return promise;
}

@@ -184,3 +182,8 @@

for (const row of rows) {
row[key + '__data'] = await access.sysSelect().where(`${col}=?`).getOne(row[key]);
const v = row[key];
if (v !== null) {
row[key + '__data'] = await access.sysSelect().where(`${col}=?`).getOne(v);
} else {
row[key + '__data'] = null;
}
}

@@ -187,0 +190,0 @@ }

{
"name": "koa-rtapi",
"version": "1.2.3",
"version": "1.2.4",
"description": "koa api in rtworld company",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc