From da50466067477ccbe8337f2b8ab51d5192cd1bdb Mon Sep 17 00:00:00 2001
From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com>
Date: Mon, 2 Nov 2020 14:21:30 +0100
Subject: [PATCH] fix(search) : use proxy

---
 api/routes.json                                   | 3 ---
 api/server.js                                     | 6 +++++-
 src/app/structure-list/services/search.service.ts | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)
 delete mode 100644 api/routes.json

diff --git a/api/routes.json b/api/routes.json
deleted file mode 100644
index 6a7af55fa..000000000
--- a/api/routes.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "/api/*": "/$1"
-}
diff --git a/api/server.js b/api/server.js
index 08ca86cb0..43c5b108c 100644
--- a/api/server.js
+++ b/api/server.js
@@ -1,13 +1,17 @@
 const jsonServer = require('json-server');
 const server = jsonServer.create();
 const router = jsonServer.router('db.json');
-const middlewares = jsonServer.defaults();
+const routes = {
+  '/api/*': '/$1',
+};
+const middlewares = [jsonServer.defaults(), jsonServer.rewriter(routes)];
 
 // Set default middlewares (logger, static, cors and no-cache)
 server.use(middlewares);
 
 // Add custom routes before JSON Server router
 server.get('/structures/count', (req, res) => {
+  console.log('ok');
   let structureCountTab = [];
   // Compétences de base
   structureCountTab.push({ id: 260, count: 3 });
diff --git a/src/app/structure-list/services/search.service.ts b/src/app/structure-list/services/search.service.ts
index fc3e73583..906fc3aee 100644
--- a/src/app/structure-list/services/search.service.ts
+++ b/src/app/structure-list/services/search.service.ts
@@ -17,7 +17,7 @@ export class SearchService {
       .pipe(map((data: any[]) => data.map((item) => new Category(item))));
   }
   public getFakeCounterModule(): Observable<any> {
-    return this.http.get('http://localhost:3000/structures/count');
+    return this.http.get('/api/structures/count');
   }
   public setCountModules(category: Category, structureCountTab: { id: number; count: number }[]): Category {
     category.modules.forEach((m: Module) => {
-- 
GitLab