Skip to content

Commit

Permalink
Added a conditional to not load the api-doc in case the .yaml does no…
Browse files Browse the repository at this point in the history
…t exist
  • Loading branch information
Mister-Mario committed Apr 25, 2024
1 parent ceac612 commit 2835435
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,19 @@ app.get('/record/:user', verifyToken, async(req, res)=>{
});

// Read the OpenAPI YAML file synchronously
const file = fs.readFileSync('./openapi.yaml', 'utf8');
const 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);
// 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));
}

// 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));

// Start the gateway service
const server = app.listen(port, () => {
Expand Down

0 comments on commit 2835435

Please sign in to comment.