diff --git a/docker-compose.yml b/docker-compose.yml index 8f4f14fa..006855b4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -91,6 +91,12 @@ services: - MM_AUTH_EMAIL_HEADER=${MM_AUTH_EMAIL_HEADER} - MM_AUTH_USER_HEADER=${MM_AUTH_USER_HEADER} - KNOWLEDGE_ADDRESS=${WHYIS_ADDRESS} + - TERM_OF_SERVICE=${TERM_OF_SERVICE} + - SWAGGER_CONTACT_NAME=${SWAGGER_CONTACT_NAME} + - SWAGGER_CONTACT_EMAIL=${SWAGGER_CONTACT_EMAIL} + - DEV_ENDPOINT=${DEV_ENDPOINT} + - QA_SERVER_ENDPOINT=${QA_SERVER_ENDPOINT} + - PROD_SERVER_ENDPOINT=${PROD_SERVER_ENDPOINT} ports: - '3001:3001' client: diff --git a/resfulservice/src/api-docs/swagger.yaml b/resfulservice/src/api-docs/swagger-service.yaml similarity index 94% rename from resfulservice/src/api-docs/swagger.yaml rename to resfulservice/src/api-docs/swagger-service.yaml index 144f7e78..883ab48c 100644 --- a/resfulservice/src/api-docs/swagger.yaml +++ b/resfulservice/src/api-docs/swagger-service.yaml @@ -5,16 +5,11 @@ info: welcome feedback and suggestions for further improvements to help you benchmark and visualize your data, explore your research hypotheses, perform simulations and analysis using our available tools, and more. version: 1.0.0 - termsOfService: https://security.duke.edu/node/82 + termsOfService: contact: - name: Marc Palmeri, Ph.D. - email: marc.j.palmeri@duke.edu + name: + email: servers: - - url: http://localhost/api - - url: https://qa.materialsmine.org/api - description: Staging server - - url: https://materialsmine.org/api - description: Production server paths: /admin/es: @@ -76,7 +71,7 @@ paths: properties: status: type: string - example: Successful + example: Successfully configured schemas! '401': description: User not authorized for this service content: diff --git a/resfulservice/src/middlewares/index.js b/resfulservice/src/middlewares/index.js index b16b4cc4..084ac43e 100644 --- a/resfulservice/src/middlewares/index.js +++ b/resfulservice/src/middlewares/index.js @@ -1,39 +1,9 @@ -// const bodyParser = require('body-parser'); -// const acceptedHeaders = require('./accept'); -// const getEnv = require('./parseEnv'); -// const { fileMgr, fileServer } = require('./fileStorage'); -// const { logParser, mmLogger } = require('./loggerService'); - -// const log = mmLogger(); - -// /** -// * globalMiddleWare - this function that instantiate all -// * global middleware services for the REST API -// * @param {*} app Express app object -// */ -// const globalMiddleWare = async (app) => { -// app.use(bodyParser.json()); -// app.use((req, res, next) => logParser(log, req, next)); -// app.use(fileMgr); -// app.use('/mm_files', fileServer); -// app.use(acceptedHeaders); -// app.use(getEnv); -// }; - -// /** -// * This file imports all GLOBAL middleware services & -// * exports them to the server.js file. -// */ -// module.exports = { -// log, -// globalMiddleWare -// }; - const express = require('express'); const acceptedHeaders = require('./accept'); const getEnv = require('./parseEnv'); const { fileMgr, fileServer } = require('./fileStorage'); const { logParser, mmLogger } = require('./loggerService'); +const swaggerService = require('./swagger-service'); const log = mmLogger(); @@ -58,5 +28,6 @@ const globalMiddleWare = async (app) => { */ module.exports = { log, + swaggerService, globalMiddleWare }; diff --git a/resfulservice/src/middlewares/swagger-service.js b/resfulservice/src/middlewares/swagger-service.js new file mode 100644 index 00000000..741647c7 --- /dev/null +++ b/resfulservice/src/middlewares/swagger-service.js @@ -0,0 +1,24 @@ +const path = require('path'); +const yaml = require('yamljs'); + +const contractDocumentPath = path.resolve(__dirname, '../api-docs/swagger-service.yaml'); + +// Serve the Swagger UI +module.exports = (env) => { + const contractDocument = yaml.load(contractDocumentPath); + contractDocument && (contractDocument.info.termsOfService = env.TERM_OF_SERVICE ?? ''); + contractDocument && (contractDocument.info.contact.name = env.SWAGGER_CONTACT_NAME ?? ''); + contractDocument && (contractDocument.info.contact.email = env.SWAGGER_CONTACT_EMAIL ?? ''); + contractDocument && (contractDocument.servers = [ + { url: env.DEV_ENDPOINT ?? '' }, + { + url: env.QA_SERVER_ENDPOINT ?? undefined, + description: 'Staging server' + }, + { + url: env.PROD_SERVER_ENDPOINT ?? undefined, + description: 'Production server' + } + ].filter((service) => !!service.url && service)); + return contractDocument; +}; diff --git a/resfulservice/src/server.js b/resfulservice/src/server.js index 6321dc1e..110078e9 100644 --- a/resfulservice/src/server.js +++ b/resfulservice/src/server.js @@ -5,10 +5,8 @@ const mongoose = require('mongoose'); const { createServer: createHttpServer } = require('http'); const { WebSocketServer } = require('ws'); const { useServer: useWsServer } = require('graphql-ws/lib/use/ws'); -const path = require('path'); const swaggerUi = require('swagger-ui-express'); -const yaml = require('yamljs'); -const { globalMiddleWare, log } = require('./middlewares'); +const { globalMiddleWare, log, swaggerService } = require('./middlewares'); const adminRoutes = require('./routes/admin'); const authRoutes = require('./routes/authService'); const curationRoutes = require('./routes/curation'); @@ -23,7 +21,6 @@ const typeDefs = require('./graphql'); const getHttpContext = require('./graphql/context/getHttpContext'); const getWsContext = require('./graphql/context/getWsContext'); -const swaggerDocumentPath = path.resolve(__dirname, './api-docs/swagger.yaml'); const env = process.env; const app = express(); @@ -31,8 +28,8 @@ globalMiddleWare(app); elasticSearch.ping(log); // Serve the Swagger UI -const swaggerDocument = yaml.load(swaggerDocumentPath); -app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, { explorer: true })); +const apiContractDocument = swaggerService(env); +app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(apiContractDocument, { explorer: true })); app.use('/admin', adminRoutes); app.use('/curate', curationRoutes);