Commit 3c790b94 authored by 智勇's avatar 智勇

statistic

parent 4fc93e46
const Router = require('koa-router'); const Router = require('koa-router');
const bodyParser = require('koa-bodyparser')
const config = require('../../src'); const config = require('../../src');
const { StatisticsLog } = require('../service/mongoService');
const api = async function (ctx) { const api = async function (ctx) {
await ctx.pipe({ await ctx.pipe({
uri: config.api.tke_api + ctx.url.replace('/k8s', ''), uri: config.api.tke_api + ctx.url.replace('/k8s', ''),
}) })
if (ctx.request.method === 'POST' && ctx.response.status === 200 && ctx.request.url.indexOf('/service') !== -1) {
const user = await ctx.redisGet(config.QA_TOKEN, ctx.request.header['x-token'])
const body = ctx.request.body
const data = {
namespace: body.namespace,
active: ctx.request.url.replace('/k8s/', '').replace('/', '_'),
microservice_name: body.serviceName,
user: user && user.cn,
user_mail: user && user.mail,
detail: body,
}
await StatisticsLog.saveLog(data);
}
} }
const router = new Router(); const router = new Router();
router router
.use(bodyParser())
.get('/*', api) .get('/*', api)
.post('/*', api) .post('/*', api)
module.exports = router module.exports = router
...@@ -42,7 +42,7 @@ const schema = new Schema({ ...@@ -42,7 +42,7 @@ const schema = new Schema({
}) })
schema.statics.getActiveProjectsHostName = function () { schema.statics.getActiveProjectsHostName = function () {
return this.find({ des: { $ne: '海外' }, is_active: 1 }).select(['host_name', 'project_name', 'type']).lean().then((res) => { return this.find({ des: { $ne: '海外' } }).select(['host_name', 'project_name', 'type']).lean().then((res) => {
const reg = /^([\w-\.]+)\.[\w-]+\.[a-z]+$/ const reg = /^([\w-\.]+)\.[\w-]+\.[a-z]+$/
// 转为对象形式 // 转为对象形式
const o = res.reduce((prev, next) => { const o = res.reduce((prev, next) => {
......
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