[react-express-mongdb] use compose network to communicate between services (#62)
Signed-off-by: Guillaume Lours <guillaume.lours@docker.com>
This commit is contained in:
parent
2f750eb4f7
commit
e29f0d1c54
@ -13,6 +13,10 @@ services:
|
|||||||
- /usr/src/app/node_modules
|
- /usr/src/app/node_modules
|
||||||
container_name: frontend
|
container_name: frontend
|
||||||
restart: always
|
restart: always
|
||||||
|
networks:
|
||||||
|
- react-express
|
||||||
|
depends_on:
|
||||||
|
- server
|
||||||
server:
|
server:
|
||||||
container_name: server
|
container_name: server
|
||||||
restart: always
|
restart: always
|
||||||
@ -20,18 +24,24 @@ services:
|
|||||||
context: server
|
context: server
|
||||||
args:
|
args:
|
||||||
NODE_PORT: 3000
|
NODE_PORT: 3000
|
||||||
ports:
|
|
||||||
- 3000:3000
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./server:/usr/src/app
|
- ./server:/usr/src/app
|
||||||
- /usr/src/app/node_modules
|
- /usr/src/app/node_modules
|
||||||
depends_on:
|
depends_on:
|
||||||
- mongo
|
- mongo
|
||||||
|
networks:
|
||||||
|
- express-mongo
|
||||||
|
- react-express
|
||||||
|
|
||||||
mongo:
|
mongo:
|
||||||
container_name: mongo
|
container_name: mongo
|
||||||
restart: always
|
restart: always
|
||||||
image: mongo:4.2.0
|
image: mongo:4.2.0
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/data/db
|
- ./data:/data/db
|
||||||
ports:
|
networks:
|
||||||
- 27017:27017
|
- express-mongo
|
||||||
|
networks:
|
||||||
|
react-express:
|
||||||
|
express-mongo:
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": "react-app"
|
"extends": "react-app"
|
||||||
},
|
},
|
||||||
|
"proxy": "http://server:3000",
|
||||||
"browserslist": {
|
"browserslist": {
|
||||||
"production": [
|
"production": [
|
||||||
">0.2%",
|
">0.2%",
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
const config = {
|
|
||||||
API_BASE_URL: 'http://localhost:3000',
|
|
||||||
};
|
|
||||||
|
|
||||||
export default config;
|
|
@ -1,12 +1,10 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import config from '../config/constants';
|
|
||||||
|
|
||||||
|
|
||||||
export async function request (method, uri, data, headers = null, params = null) {
|
export function request (method, uri, data, headers = null, params = null) {
|
||||||
let url = (config.API_BASE_URL + uri);
|
|
||||||
let query = {
|
let query = {
|
||||||
method: method,
|
method,
|
||||||
url: url
|
url: uri
|
||||||
};
|
};
|
||||||
if (headers !== null)
|
if (headers !== null)
|
||||||
query.headers = headers;
|
query.headers = headers;
|
||||||
@ -14,9 +12,5 @@ export async function request (method, uri, data, headers = null, params = null)
|
|||||||
query.params = params;
|
query.params = params;
|
||||||
if (method === 'post' || method === 'put' || method === 'delete' || method === 'patch')
|
if (method === 'post' || method === 'put' || method === 'delete' || method === 'patch')
|
||||||
query.data = data;
|
query.data = data;
|
||||||
try {
|
return axios(query);
|
||||||
return await axios(query);
|
}
|
||||||
} catch (e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user