浏览代码

添加关键字检索接口

asd123a20 2 年之前
父节点
当前提交
040b7e7f26

+ 4 - 0
service-cms/app/controller/content.js

@@ -22,6 +22,10 @@ class ContentController extends Controller {
     const res = await this.ctx.service.content.fetch(this.ctx.query);
     this.ctx.body = res;
   }
+  async search() {
+    const res = await this.ctx.service.content.search(this.ctx.query);
+    this.ctx.body = res;
+  }
 }
 
 module.exports = ContentController;

+ 1 - 0
service-cms/app/router.js

@@ -16,6 +16,7 @@ module.exports = app => {
   router.delete('/api/cms/contents/delete/:id', controller.content.delete);
   router.get('/api/cms/contents/query', controller.content.query);
   router.get('/api/cms/contents/fetch', controller.content.fetch);
+  router.get('/api/cms/contents/search', controller.content.search);
   // 图片新闻类型
   router.post('/api/cms/imgtype/create', controller.imgtype.create);
   router.post('/api/cms/imgtype/update', controller.imgtype.update);

+ 9 - 0
service-cms/app/service/content.js

@@ -100,6 +100,15 @@ class ContentService extends Service {
       throw error;
     }
   }
+  async search({ search }) {
+    try {
+      const list = await this.model.find();
+      const res = list.filter(e => (e.content.includes(search) || e.title.includes(search)));
+      return { errcode: 0, errmsg: '', data: res };
+    } catch (error) {
+      throw error;
+    }
+  }
 }
 
 module.exports = ContentService;

+ 6 - 6
service-code/config/config.default.js

@@ -35,13 +35,13 @@ module.exports = appInfo => {
   };
   // 数据库配置
   config.mongoose = {
-    url: 'mongodb://172.17.116.7/Microservices',
+    url: 'mongodb://127.0.0.1/Microservices',
     options: {
-      user: 'root',
-      pass: 'Ziyouyanfa#@!',
-      authSource: 'admin',
-      useNewUrlParser: true,
-      useCreateIndex: true,
+      // user: 'root',
+      // pass: 'Ziyouyanfa#@!',
+      // authSource: 'admin',
+      // useNewUrlParser: true,
+      // useCreateIndex: true,
     },
   };
   config.logger = {

+ 6 - 6
service-files/config/config.default.js

@@ -37,13 +37,13 @@ module.exports = appInfo => {
   };
   // 数据库配置
   config.mongoose = {
-    url: 'mongodb://172.17.116.7/Microservices',
+    url: 'mongodb://127.0.0.1/Microservices',
     options: {
-      user: 'root',
-      pass: 'Ziyouyanfa#@!',
-      authSource: 'admin',
-      useNewUrlParser: true,
-      useCreateIndex: true,
+      // user: 'root',
+      // pass: 'Ziyouyanfa#@!',
+      // authSource: 'admin',
+      // useNewUrlParser: true,
+      // useCreateIndex: true,
     },
   };
   // 文件存储路径

+ 6 - 0
service-gateway/config/cms.js

@@ -57,6 +57,12 @@ module.exports = [
     issuer: [ 'naf' ],
     log: false,
   },
+  {
+    url: '/api/cms/contents/search',
+    jwt: false,
+    issuer: [ 'naf' ],
+    log: false,
+  },
   // 图片新闻类型
   {
     url: '/api/cms/imgtype/create',

+ 6 - 6
service-log/config/config.default.js

@@ -36,13 +36,13 @@ module.exports = appInfo => {
   };
   // 数据库配置
   config.mongoose = {
-    url: 'mongodb://172.17.116.7/Microservices',
+    url: 'mongodb://127.0.0.1/Microservices',
     options: {
-      user: 'root',
-      pass: 'Ziyouyanfa#@!',
-      authSource: 'admin',
-      useNewUrlParser: true,
-      useCreateIndex: true,
+      // user: 'root',
+      // pass: 'Ziyouyanfa#@!',
+      // authSource: 'admin',
+      // useNewUrlParser: true,
+      // useCreateIndex: true,
     },
   };
   config.logger = {

+ 9 - 8
service-login/config/config.default.js

@@ -36,20 +36,21 @@ module.exports = appInfo => {
   };
   // 数据库配置
   config.mongoose = {
-    url: 'mongodb://172.17.116.7/Microservices',
+    url: 'mongodb://127.0.0.1/Microservices',
     options: {
-      user: 'root',
-      pass: 'Ziyouyanfa#@!',
-      authSource: 'admin',
-      useNewUrlParser: true,
-      useCreateIndex: true,
+      // user: 'root',
+      // pass: 'Ziyouyanfa#@!',
+      // authSource: 'admin',
+      // useNewUrlParser: true,
+      // useCreateIndex: true,
     },
   };
   config.redis = {
     client: {
-      port: 6389, // 部署
-      // port: 6379,
+      // port: 6389, // 部署
+      port: 6379,
       host: '127.0.0.1',
+      // password: 'Ziyouyanfa#@!',
       password: null,
       db: 0,
     },

+ 6 - 6
service-naf/config/config.default.js

@@ -36,13 +36,13 @@ module.exports = appInfo => {
   };
   // 数据库配置
   config.mongoose = {
-    url: 'mongodb://172.17.116.7/Microservices',
+    url: 'mongodb://127.0.0.1/Microservices',
     options: {
-      user: 'root',
-      pass: 'Ziyouyanfa#@!',
-      authSource: 'admin',
-      useNewUrlParser: true,
-      useCreateIndex: true,
+      // user: 'root',
+      // pass: 'Ziyouyanfa#@!',
+      // authSource: 'admin',
+      // useNewUrlParser: true,
+      // useCreateIndex: true,
     },
   };
   config.logger = {