From 283543586ee5c80c0ac5d33190fc74bc61489a38 Mon Sep 17 00:00:00 2001
From: Mister-Mario <mariojr2003@gmail.com>
Date: Thu, 25 Apr 2024 12:37:16 +0200
Subject: [PATCH] Added a conditional to not load the api-doc in case the .yaml
 does not exist

---
 gatewayservice/gateway-service.js | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js
index f592f9e..62b3dc8 100644
--- a/gatewayservice/gateway-service.js
+++ b/gatewayservice/gateway-service.js
@@ -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, () => {