Skip to content

Commit

Permalink
[react-express-mongdb] use compose network to communicate between ser…
Browse files Browse the repository at this point in the history
…vices (docker#62)

Signed-off-by: Guillaume Lours <guillaume.lours@docker.com>
  • Loading branch information
glours authored May 12, 2020
1 parent 2f750eb commit e29f0d1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
18 changes: 14 additions & 4 deletions react-express-mongodb/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,35 @@ services:
- /usr/src/app/node_modules
container_name: frontend
restart: always
networks:
- react-express
depends_on:
- server
server:
container_name: server
restart: always
build:
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 change: 1 addition & 0 deletions react-express-mongodb/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"eslintConfig": {
"extends": "react-app"
},
"proxy": "http://server:3000",
"browserslist": {
"production": [
">0.2%",
Expand Down
5 changes: 0 additions & 5 deletions react-express-mongodb/frontend/src/config/constants.js

This file was deleted.

16 changes: 5 additions & 11 deletions react-express-mongodb/frontend/src/utilities/httpRequestHandler.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
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;
if (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);
}

0 comments on commit e29f0d1

Please sign in to comment.