Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uo289659 #95

Merged
merged 9 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ services:
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb

statisticsservice:
container_name: statisticsservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es3a/statisticsservice:latest
profiles: ["dev", "prod"]
build: ./statistics/statisticsservice
depends_on:
- mongodb
ports:
- "8006:8006"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb



gatewayservice:
container_name: gatewayservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es3a/gatewayservice:latest
Expand All @@ -73,6 +89,7 @@ services:
- userservice
- authservice
- generatorservice
- statisticsservice
- questionservice
ports:
- "8000:8000"
Expand All @@ -81,9 +98,11 @@ services:
environment:
AUTH_SERVICE_URL: http://authservice:8002
USER_SERVICE_URL: http://userservice:8001
STATS_SERVICE_URL: http://statisticsservice:8006
GENERATOR_SERVICE_URL: http://generatorservice:8003
QUESTION_SERVICE_URL: http://questionservice:8004


webapp:
container_name: webapp-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es3a/webapp:latest
Expand All @@ -93,6 +112,8 @@ services:
- gatewayservice
ports:
- "3000:3000"
environment:
GATEWAY_SERVICE_URL: http://gatewayservice:8000

prometheus:
image: prom/prometheus
Expand Down Expand Up @@ -135,4 +156,4 @@ volumes:

networks:
mynetwork:
driver: bridge
driver: bridge
22 changes: 22 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ const port = 8000;

const authServiceUrl = process.env.AUTH_SERVICE_URL || 'http://localhost:8002';
const userServiceUrl = process.env.USER_SERVICE_URL || 'http://localhost:8001';
const statisticssServiceUrl = process.env.STATS_SERVICE_URL || 'http://localhost:8006';
const generatorServiceUrl = process.env.GENERATOR_SERVICE_URL || 'http://localhost:8003';
const questionServiceUrl = process.env.QUESTION_SERVICE_URL || 'http://localhost:8004';


app.use(cors());
app.use(express.json());

Expand Down Expand Up @@ -57,6 +59,13 @@ app.get('/generate-question', async (req, res) => {
}
});


app.get('/statistics', async (req, res) => {
try {
const questionResponse = await axios.get(statisticssServiceUrl+'/statistics', {
params: req.query,
});

app.get('/questions', async (req, res) => {
try {
// Forward the get questions request to the question service
Expand All @@ -68,6 +77,18 @@ app.get('/questions', async (req, res) => {
});


app.post('/addStatistic', async (req, res) => {
try {
const questionResponse = await axios.post(statisticssServiceUrl+'/addStatistic',
req.body,
);
res.json(questionResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});


// Read the OpenAPI YAML file synchronously
openapiPath='./openapi.yaml'
if (fs.existsSync(openapiPath)) {
Expand All @@ -84,6 +105,7 @@ if (fs.existsSync(openapiPath)) {
console.log("Not configuring OpenAPI. Configuration file not present.")
}


// Start the gateway service
const server = app.listen(port, () => {
console.log(`Gateway Service listening at http://localhost:${port}`);
Expand Down
Loading
Loading