Skip to content

Commit

Permalink
Merge pull request #87 from Arquisoft/jota
Browse files Browse the repository at this point in the history
Cambios OpenAPI
  • Loading branch information
UO277938 authored Apr 8, 2024
2 parents 85affa7 + 95eec4d commit 67380e4
Show file tree
Hide file tree
Showing 16 changed files with 648 additions and 195 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
- run: npm --prefix userservice/authservice test -- --coverage
- run: npm --prefix userservice/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
#- run: npm --prefix questionservice test -- --coverage
#- run: npm --prefix webapp test -- --coverage
- run: npm --prefix questionservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ jobs:
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Update OpenAPI configuration
run: |
DEPLOY_HOST=${{ secrets.DEPLOY_HOST }}
sed -i "s/SOMEIP/${DEPLOY_HOST}/g" gatewayservice/openapi.yaml
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
Expand Down
32 changes: 25 additions & 7 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ const axios = require('axios');
const cors = require('cors');
const promBundle = require('express-prom-bundle');

//librerias para OpenAPI-Swagger
const swaggerUi = require('swagger-ui-express');
const fs = require("fs");
const YAML = require('yaml');

const app = express();
const port = 8000;

const userServiceUrl = process.env.USER_SERVICE_URL || 'http://localhost:8001';
const authServiceUrl = process.env.AUTH_SERVICE_URL || 'http://localhost:8002';
const questionServiceUrl = process.env.QUESTION_SERVICE_URL || 'http://localhost:8003';
const statServiceUrl = process.env.STAT_SERVICE_URL || 'http://localhost:8004';

app.use(cors());
app.use(express.json());
Expand Down Expand Up @@ -54,28 +58,26 @@ app.get('/pregunta', async (req, res) => {

app.get('/updateCorrectAnswers', async (req, res) => {
console.log(req.query)
const { username } = req.query;
const params = {username: req.query.username, numAnswers: req.query.numAnswers};
try{
const updateStatsResponse = await axios.get(userServiceUrl+ `/updateCorrectAnswers?username=${username}`)
const updateStatsResponse = await axios.get(userServiceUrl+ `/updateCorrectAnswers?params=${params}`)
res.json(updateStatsResponse.data);
}catch(error){
res.status(error.response.status).json({error: error.response.data.error});
}
});

app.get('/updateIncorrectAnswers', async (req, res) => {
console.log(req.query)
const { username } = req.query;
const params = {username: req.query.username, numAnswers: req.query.numAnswers};
try{
const updateStatsResponse = await axios.get(userServiceUrl+ `/updateIncorrectAnswers?username=${username}`)
const updateStatsResponse = await axios.get(userServiceUrl+ `/updateIncorrectAnswers?params=${params}`)
res.json(updateStatsResponse.data);
}catch(error){
res.status(error.response.status).json({error: error.response.data.error});
}
});

app.get('/updateCompletedGames', async (req, res) => {
console.log(req.query)
const { username } = req.query;
try{
const updateStatsResponse = await axios.get(userServiceUrl+ `/updateCompletedGames?username=${username}`)
Expand All @@ -98,6 +100,22 @@ app.get('/getUserData', async (req, res) => {
}
});

// Read the OpenAPI YAML file synchronously
let openapiPath='./openapi.yaml';
if (fs.existsSync(openapiPath)) {
const file = fs.readFileSync(openapiPath, 'utf8');

// Parse the YAML content into a JavaScript object representing the Swagger document
const swaggerDocument = YAML.parse(file);

// Serve the Swagger UI documentation at the '/api-doc' endpoint
// This middleware serves the Swagger UI files and sets up the Swagger UI page
// It takes the parsed Swagger document as input
app.use('/api-doc', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
} else {
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

0 comments on commit 67380e4

Please sign in to comment.