4
0
Эх сурвалжийг харах

[react-express-mongdb] use compose network to communicate between services (#62)

Signed-off-by: Guillaume Lours <guillaume.lours@docker.com>
Guillaume Lours 5 жил өмнө
parent
commit
e29f0d1c54

+ 14 - 4
react-express-mongodb/docker-compose.yml

@@ -13,6 +13,10 @@ services:
       - /usr/src/app/node_modules
     container_name: frontend
     restart: always
+    networks:
+      - react-express
+    depends_on:
+      - server
   server:
     container_name: server
     restart: always
@@ -20,18 +24,24 @@ services:
       context: server
       args:
         NODE_PORT: 3000
-    ports:
-      - 3000:3000
     volumes:
       - ./server:/usr/src/app
       - /usr/src/app/node_modules
     depends_on:
       - mongo
+    networks:
+      - express-mongo
+      - react-express
+
   mongo:
     container_name: mongo
     restart: always
     image: mongo:4.2.0
     volumes:
       - ./data:/data/db
-    ports:
-      - 27017:27017
+    networks:
+      - express-mongo
+networks:
+  react-express:
+  express-mongo:
+

+ 1 - 0
react-express-mongodb/frontend/package.json

@@ -25,6 +25,7 @@
   "eslintConfig": {
     "extends": "react-app"
   },
+  "proxy": "http://server:3000",
   "browserslist": {
     "production": [
       ">0.2%",

+ 0 - 5
react-express-mongodb/frontend/src/config/constants.js

@@ -1,5 +0,0 @@
-const config = {
-    API_BASE_URL: 'http://localhost:3000',
-};
-
-export default config;

+ 5 - 11
react-express-mongodb/frontend/src/utilities/httpRequestHandler.js

@@ -1,12 +1,10 @@
 import axios from 'axios';
-import config from '../config/constants';
 
 
-export async function request (method, uri, data, headers = null, params = null) {
-    let url = (config.API_BASE_URL + uri);
+export function request (method, uri, data, headers = null, params = null) {
     let query = {
-        method: method,
-        url: url
+        method,
+        url: uri
     };
     if (headers !== null)
         query.headers = headers;
@@ -14,9 +12,5 @@ export async function request (method, uri, data, headers = null, params = null)
         query.params = params;
     if (method === 'post' || method === 'put' || method === 'delete' || method === 'patch')
         query.data = data;
-    try {
-        return await axios(query);
-    } catch (e) {
-         throw e;
-    }
-}
+    return axios(query);
+}