Skip to content

Commit

Permalink
Merge pull request #81 from Arquisoft/OpenApi+pre-v0.2.0
Browse files Browse the repository at this point in the history
Open api+pre v0.2.0
  • Loading branch information
adriiglz authored Mar 31, 2024
2 parents 082c2c3 + 2a72cb9 commit a4c61b7
Show file tree
Hide file tree
Showing 9 changed files with 648 additions and 79 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ docker compose --profile dev up --build
## Meet our Team
We are students of Software Architecture in the University of Oviedo. This web application is the laboratory project of the subject. We hope you like our webapp and we are welcomed to proposals of new content by our Issues.

You can check our Documentation [here](https://arquisoft.github.io/wiq_en1a/) where all the tecnical details are explained
You can check our Documentation [here](https://arquisoft.github.io/wiq_en1a/) where all the tecnical details are explained. Moreover, you can check our API for your free use, using Swagger, [here](http://158.179.217.182:8000/api-doc).

### Developers

Expand Down
37 changes: 22 additions & 15 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const axios = require('axios');
const cors = require('cors');
const promBundle = require('express-prom-bundle');

//libraries required for OpenAPI-Swagger
const swaggerUi = require('swagger-ui-express');
const fs = require("fs")
const YAML = require('yaml')

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

Expand Down Expand Up @@ -75,21 +80,6 @@ app.post('/imgs/answer', async (req, res) => {
});


app.get('/self', async (req, res) => {
try {
// Forward the self request to the user service

const userResponse = await axios.get(authServiceUrl+'/self', {
headers: {
Authorization: req.headers.authorization,
},
});

res.status(200).json(userResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});
app.get('/rankings', async (req, res) => {
try {
// Forward the request to the user service
Expand All @@ -100,9 +90,26 @@ app.get('/rankings', async (req, res) => {
}
});

// Read the OpenAPI YAML file synchronously
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}`);
});


module.exports = server
Loading

0 comments on commit a4c61b7

Please sign in to comment.