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

Open api+pre v0.2.0 #81

Merged
merged 2 commits into from
Mar 31, 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
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
Loading