diff --git a/docs/README.md b/docs/README.md index b1c9207..5d0cf09 100644 --- a/docs/README.md +++ b/docs/README.md @@ -138,6 +138,9 @@ module.exports.handler = serverless(service) // - If it returns `null`, no proxy will be used and the default factory will be skipped entirely. // Default: the built-in proxy factory from `fast-gateway` proxyFactory: ({ proxyType, opts, route }) => {...} + // Optional toggle for exposing minimal documentation of registered services at `GET /services.json` + // Default value: true + enableServicesEndpoint: true // HTTP proxy routes: [{ @@ -214,6 +217,8 @@ For developers reference, default hooks implementation are located in `lib/defau Since version `1.3.5` the gateway exposes minimal documentation about registered services at: `GET /services.json` +Since version `4.2.0`, the `/services.json` route can be disabled by setting `enableServicesEndpoint: false` in the gateway options. + Example output: ```json diff --git a/index.d.ts b/index.d.ts index 8d1da52..67289dc 100644 --- a/index.d.ts +++ b/index.d.ts @@ -76,6 +76,7 @@ declare namespace fastgateway { pathRegex?: string timeout?: number targetOverride?: string + enableServicesEndpoint?: boolean routes: (Route | WebSocketRoute)[] } } diff --git a/index.js b/index.js index 6669738..3d2b8b7 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,6 @@ const DEFAULT_METHODS = require('restana/libs/methods').filter( (method) => method !== 'all' ) const NOOP = (req, res) => {} -const send = require('@polka/send-type') const PROXY_TYPES = ['http', 'lambda'] const registerWebSocketRoutes = require('./lib/ws-proxy') @@ -29,7 +28,8 @@ const gateway = (opts) => { opts = Object.assign( { middlewares: [], - pathRegex: '/*' + pathRegex: '/*', + enableServicesEndpoint: true }, opts ) @@ -46,9 +46,13 @@ const gateway = (opts) => { prefix: route.prefix, docs: route.docs })) - router.get('/services.json', (req, res) => { - send(res, 200, services) - }) + if (opts.enableServicesEndpoint) { + router.get('/services.json', (req, res) => { + res.statusCode = 200 + res.setHeader('Content-Type', 'application/json') + res.end(JSON.stringify(services)) + }) + } // processing websocket routes const wsRoutes = opts.routes.filter( diff --git a/package.json b/package.json index dd10036..2dc4438 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,6 @@ "LICENSE" ], "devDependencies": { - "@polka/send-type": "^0.5.2", "@types/node": "^22.13.11", "@types/express": "^5.0.0", "artillery": "^2.0.21",