Commit 13a71b11 authored by wmvm's avatar wmvm

update

parent 5a65ee63
...@@ -4,7 +4,7 @@ import _ from 'lodash'; ...@@ -4,7 +4,7 @@ import _ from 'lodash';
const env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development'; const env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development';
const config_file = './config.' + env; const config_file = './config.' + env;
const common_config = require('@broker/nodejs_common').config; const common_config = require('@madex/ex-js-common').config;
export default _.merge( export default _.merge(
{ {
......
import express, { Request, Response, NextFunction } from 'express'; let express = require('express');
import errorHandler from 'errorhandler'; let errorHandler = require('errorhandler');
import morgan from 'morgan'; let logger = require("@madex/ex-js-public").logger;
import { logger, expressSetting } from '@broker/nodejs_common';
import appConfig from "./config";
import { apiRouterV1 } from "./src/functional/router/v1";
const app = express();
expressSetting(app); /* ======================================================================
app.use(morgan('dev')); * Config
* ====================================================================== */
let app = express();
if (appConfig.node_env === 'development') {
logger.use(app);
const tfUrl = "/api/v1/tf";
// express 全局设定
require('@madex/ex-js-common').expressSetting(app);
// Request frequency limit
const limitList = [
"transfer/transferInList",
"transfer/transferOutList",
"transfer/bills",
];
require("@madex/ex-js-common").frequencyLimiting.cookieLimitForCmd(app, limitList);
require("@madex/ex-js-common").apiExceedAlertUtils.check(app, { projectNO: 20, expireTime: 1000 }) // 检查
import configSetting from "./config"
if (configSetting.node_env == "development") {
app.use(errorHandler()); app.use(errorHandler());
} }
else { else {
app.use((err: any, req: Request, res: Response, next: NextFunction) => { app.use(function (err, req, resp, next) {
res.status(500).send("500 error"); logger.warn('500 error ', err);
return resp.status(500).send();
}); });
} }
/* ======================================================================
* internal Router
* ====================================================================== */
// require('./setting/access-limit')(app);
// require('./setting/apikey-filter')(app);
// require('./setting/need-login')(app);
// require('./setting/need-newotc')(app);
// if (configSetting.node_env === 'development') {
// require("./setting/swagger-setting")(app);
// app.listen(3020, () => logger.info("South Gate to Heaven swagger started!! suffix : 3020/southHeaven"));
// }
import { apiRouterV1 } from "./src/functional/router/v1/index"
app.use('/demo/v1', apiRouterV1); app.use('/demo/v1', apiRouterV1);
app.listen(appConfig.port, '0.0.0.0', () => {
//启动Server
// app.listen(configSetting.port, function () {
// // logger.info("Wallet Gateway-(bibox_b020_southgatetoheaven) server listening on %d, in %s mode", configSetting.port, app.get("env"));
// // wxUtils.serviceStartSend('bibox_b020_southgatetoheaven');
// });
// 输出进程错误
process.on('uncaughtException', (error) => {
let error_msg = JSON.stringify(error)
logger.error("uncaughtException:", error_msg)
})
// 输出未捕获异常
process.on('unhandledRejection', (error, promise) => {
promise.catch(err => {
logger.warn("unhandledRejection:", JSON.stringify(err.message))
})
});
// console.log(configSetting)
app.listen(configSetting.port, '0.0.0.0', () => {
logger.info( logger.info(
'MyToken-(api) server listening on %d, in %s mode', 'demo',
appConfig.port, configSetting.port,
app.get('env'), app.get('env'),
); );
}); });
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -37,23 +37,44 @@ ...@@ -37,23 +37,44 @@
"typescript": "^5.4.3" "typescript": "^5.4.3"
}, },
"dependencies": { "dependencies": {
"@ex/nodejs_common": "git+ssh://git@bitbucket.org:biiigle/ex-js-common.git#master", "@madex/ex-js-common": "git+ssh://git@bitbucket.org:biiigle/ex-js-common.git#master",
"@broker/nodejs_dao_next": "1.10.0", "@madex/ex-js-public": "git+ssh://git@bitbucket.org:biiigle/ex-js-public.git#master",
"@madex/ex-ts-dao": "0.0.2",
"@types/errorhandler": "^1.5.3", "@types/errorhandler": "^1.5.3",
"@types/express": "^4.17.21", "@types/express": "^4.17.21",
"@types/morgan": "^1.9.9", "@types/morgan": "^1.9.9",
"async": "^2.6.4",
"axios": "1.7.2", "axios": "1.7.2",
"bignumber.js": "^4.0.4",
"body-parser": "^1.20.2",
"chai": "^4.3.7",
"compression": "^1.7.4",
"concat-stream": "^2.0.0",
"cookie-parser": "^1.4.4",
"cryptiles": "^3.1.4",
"crypto-js": "^3.3.0",
"errorhandler": "^1.5.1", "errorhandler": "^1.5.1",
"express": "^4.18.2", "express": "^4.18.2",
"express-swagger-generator": "^1.1.17",
"geoip-lite": "^1.4.7",
"glob": "10.3.10", "glob": "10.3.10",
"isemail": "^3.2.0",
"jsonwebtoken": "^7.4.3",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"log4js": "^2.5.3",
"moment": "^2.30.1", "moment": "^2.30.1",
"morgan": "^1.10.0", "morgan": "^1.10.0",
"mysql2": "^1.7.0", "mysql2": "^1.7.0",
"node-schedule": "^2.1.1", "node-schedule": "^2.1.1",
"nodemailer": "^4.7.0",
"rate-limiter-flexible": "^5.0.3", "rate-limiter-flexible": "^5.0.3",
"redis": "^2.8.0",
"redis-connection-pool": "^1.7.4",
"reflect-metadata": "0.2.2", "reflect-metadata": "0.2.2",
"request": "^2.88.2",
"rxjs": "^7.5.7",
"sequelize": "^4.44.4", "sequelize": "^4.44.4",
"should": "^12.0.0",
"tunnel": "^0.0.6", "tunnel": "^0.0.6",
"uuid": "9.0.1" "uuid": "9.0.1"
} }
......
// nodejs_dao_next 是 ts 的 dao, 代码在 @broker/nodejs_dao 的 ts 分支上 // nodejs_dao_next 是 ts 的 dao, 代码在 @broker/nodejs_dao 的 ts 分支上
import { user } from "@broker/nodejs_dao_next"; import { userInfo } from "@madex/ex-ts-dao";
// nodejs_dao_next 在 js 项目中也可以直接使用和 @broker/nodejs_dao 的使用方式一样 // nodejs_dao_next 在 js 项目中也可以直接使用和 @broker/nodejs_dao 的使用方式一样
// 可以直接引用原有 js 封装的工具, 但是目前 js 的库没有类型提示 // 可以直接引用原有 js 封装的工具, 但是目前 js 的库没有类型提示
// 后面吧 common 用 ts 改一下就行了 // 后面吧 common 用 ts 改一下就行了
import { redisUtils } from "@broker/nodejs_common"; // import { redisUtils } from "@broker/nodejs_common";
const { redisUtilsCommon } = require('@madex/ex-js-common');
export interface UserPayload { export interface UserPayload {
email: string; email: string;
...@@ -16,20 +17,20 @@ export interface UserPayload { ...@@ -16,20 +17,20 @@ export interface UserPayload {
export const getUserInfo = async (payload: UserPayload) => { export const getUserInfo = async (payload: UserPayload) => {
const key = "ts-api-demo:user" const key = "ts-api-demo:user"
const result = await redisUtils.getSync(key) const result = await redisUtilsCommon.getSync(key)
if (result) { if (result) {
return { return {
user: result user: result
} }
} }
const dbUser = await user.prototype.findOne({ const dbUser = await userInfo.prototype.findOne({
where: { where: {
id: payload.user_id user_id: payload.user_id
}, },
raw: true raw: true
}); });
if (dbUser) { if (dbUser) {
await redisUtils.writeSync(key, dbUser, 5) await redisUtilsCommon.writeSync(key, dbUser, 5)
} }
return { return {
user: dbUser user: dbUser
......
...@@ -2,8 +2,6 @@ import Express from "express" ...@@ -2,8 +2,6 @@ import Express from "express"
const router = Express.Router(); const router = Express.Router();
const { logger, responsedata, errorCodeConst: errCode, errorCodeDefine } = require('@broker/nodejs_common');
const { getError, isValidResponseData } = responsedata;
import * as userController from "../../mvc/control/user.control" import * as userController from "../../mvc/control/user.control"
...@@ -13,16 +11,25 @@ const getFunc = { ...@@ -13,16 +11,25 @@ const getFunc = {
const postFunc = {}; const postFunc = {};
let getErrorMessage = (code: number, message?: string) => {
return {
code: code,
msg: message,
data: [],
};
};
// TODO 这里先和 nodejs 的注册路由方式保持一样,后面在调整。 // TODO 这里先和 nodejs 的注册路由方式保持一样,后面在调整。
router.get('/*', (req, res, next) => { router.get('/*', (req, res, next) => {
let path = req.path ? req.path.slice(1) : ''; let path = req.path ? req.path.slice(1) : '';
if (!path) { if (!path) {
return res.json(getError(errCode.CODE_NEED_ROUTER)); return res.json(getErrorMessage(3000));
} }
if (!getFunc[path]) { if (!getFunc[path]) {
return res.json(getError(errCode.CODE_UNDEFINE_ROUTER)); return res.json(getErrorMessage(3000));
} }
doJob(req, res, next, req.query, getFunc[path]); doJob(req, res, next, req.query, getFunc[path]);
...@@ -31,11 +38,11 @@ router.get('/*', (req, res, next) => { ...@@ -31,11 +38,11 @@ router.get('/*', (req, res, next) => {
router.post('/*', (req, res, next) => { router.post('/*', (req, res, next) => {
const path = req.path ? req.path.slice(1) : ''; const path = req.path ? req.path.slice(1) : '';
if (!path) { if (!path) {
return res.json(getError(errCode.CODE_NEED_ROUTER)); return res.json(getErrorMessage(3000));
} }
if (!postFunc[path]) { if (!postFunc[path]) {
return res.json(getError(errCode.CODE_UNDEFINE_ROUTER)); return res.json(getErrorMessage(3000));
} }
doJob(req, res, next, req.body, postFunc[path]); doJob(req, res, next, req.body, postFunc[path]);
...@@ -49,15 +56,15 @@ const doJob = (req, res, next, param, func) => { ...@@ -49,15 +56,15 @@ const doJob = (req, res, next, param, func) => {
func(req, param).then(data => { func(req, param).then(data => {
res.json(data); res.json(data);
}).catch(err => { // 可以抛出错误码 }).catch(err => { // 可以抛出错误码
logger.warn(_func_name_, err); console.error(_func_name_, err);
if (isValidResponseData(err)) { // if (isValidResponseData(err)) {
res.json(err); // res.json(err);
return; // return;
} // }
if (!err || !errorCodeDefine[err]) { // if (!err || !errorCodeDefine[err]) {
err = errCode.CODE_INTERNAL; // err = errCode.CODE_INTERNAL;
} // }
res.json(getError(err)); return res.json(getErrorMessage(3000));
}); });
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment