From 41c55ed7c93b87503e1105080ba0d54f7f155c90 Mon Sep 17 00:00:00 2001 From: Vincent de Vreede Date: Tue, 13 May 2025 07:35:29 +0200 Subject: [PATCH 1/3] chore(gateway): remove @polka/send-type dependency --- index.js | 5 +++-- package.json | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 6669738..cede7fc 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') @@ -47,7 +46,9 @@ const gateway = (opts) => { docs: route.docs })) router.get('/services.json', (req, res) => { - send(res, 200, services) + res.statusCode = 200 + res.setHeader('Content-Type', 'application/json') + res.end(JSON.stringify(services)) }) // processing websocket routes 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", From 38b489e7b266ece50b5a72428d0470035a1d0d67 Mon Sep 17 00:00:00 2001 From: Vincent de Vreede Date: Tue, 13 May 2025 07:36:37 +0200 Subject: [PATCH 2/3] feat(gateway): add servicesJsonRoute option to control documentation exposure --- docs/README.md | 5 +++++ index.d.ts | 1 + index.js | 15 +++++++++------ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index b1c9207..eb8eb2f 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 + servicesJsonRoute: 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 `servicesJsonRoute: false` in the gateway options. + Example output: ```json diff --git a/index.d.ts b/index.d.ts index 8d1da52..af6eb0b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -76,6 +76,7 @@ declare namespace fastgateway { pathRegex?: string timeout?: number targetOverride?: string + servicesJsonRoute?: boolean routes: (Route | WebSocketRoute)[] } } diff --git a/index.js b/index.js index cede7fc..9f7048d 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,8 @@ const gateway = (opts) => { opts = Object.assign( { middlewares: [], - pathRegex: '/*' + pathRegex: '/*', + servicesJsonRoute: true }, opts ) @@ -45,11 +46,13 @@ const gateway = (opts) => { prefix: route.prefix, docs: route.docs })) - router.get('/services.json', (req, res) => { - res.statusCode = 200 - res.setHeader('Content-Type', 'application/json') - res.end(JSON.stringify(services)) - }) + if (opts.servicesJsonRoute) { + 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( From febdf5155ffa12c774031cc64f891f904c3af5cd Mon Sep 17 00:00:00 2001 From: Vincent de Vreede Date: Thu, 15 May 2025 22:21:52 +0200 Subject: [PATCH 3/3] refactor: rename servicesJsonRoute to enableServicesEndpoint for clarity --- docs/README.md | 4 ++-- index.d.ts | 2 +- index.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/README.md b/docs/README.md index eb8eb2f..5d0cf09 100644 --- a/docs/README.md +++ b/docs/README.md @@ -140,7 +140,7 @@ module.exports.handler = serverless(service) proxyFactory: ({ proxyType, opts, route }) => {...} // Optional toggle for exposing minimal documentation of registered services at `GET /services.json` // Default value: true - servicesJsonRoute: true + enableServicesEndpoint: true // HTTP proxy routes: [{ @@ -217,7 +217,7 @@ 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 `servicesJsonRoute: false` in the gateway options. +Since version `4.2.0`, the `/services.json` route can be disabled by setting `enableServicesEndpoint: false` in the gateway options. Example output: diff --git a/index.d.ts b/index.d.ts index af6eb0b..67289dc 100644 --- a/index.d.ts +++ b/index.d.ts @@ -76,7 +76,7 @@ declare namespace fastgateway { pathRegex?: string timeout?: number targetOverride?: string - servicesJsonRoute?: boolean + enableServicesEndpoint?: boolean routes: (Route | WebSocketRoute)[] } } diff --git a/index.js b/index.js index 9f7048d..3d2b8b7 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,7 @@ const gateway = (opts) => { { middlewares: [], pathRegex: '/*', - servicesJsonRoute: true + enableServicesEndpoint: true }, opts ) @@ -46,7 +46,7 @@ const gateway = (opts) => { prefix: route.prefix, docs: route.docs })) - if (opts.servicesJsonRoute) { + if (opts.enableServicesEndpoint) { router.get('/services.json', (req, res) => { res.statusCode = 200 res.setHeader('Content-Type', 'application/json')