diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index fd119044..5390811e 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -46,15 +46,21 @@ app.post('/adduser', async (req, res) => { }); // Read the OpenAPI YAML file synchronously -const file = fs.readFileSync('./openapi.yaml', 'utf8'); +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)); +} else { + console.log("Not configuring OpenAPI. Configuration file not present.") +} -// 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, () => {