react-frontend: build: ./frontend/react-app ports: - "3000:3000" environment: - REACT_APP_API_URL=http://api-gateway:5000
app.post('/users', async (req, res) => { const newUser = new User(req.body); await newUser.save(); res.status(201).json(newUser); });
const User = mongoose.model('User', userSchema);
app.listen(5000, () => { console.log('API Gateway running on port 5000'); });
import React, { useState, useEffect } from 'react'; import axios from 'axios'; const API_GATEWAY = 'http://localhost:5000';
microservices-app/ ├── api-gateway/ ├── services/ │ ├── user-service/ │ ├── product-service/ │ └── order-service/ ├── frontend/ │ └── react-app/ └── docker-compose.yml 2.1 Initialize the Service cd services/user-service npm init -y npm install express mongoose cors dotenv 2.2 Create the Server server.js
Recent Comments