Skip to content

Commit b6d85ee

Browse files
Add enableServicesEndpoint option and remove unneeded dependency (#99)
* chore(gateway): remove @polka/send-type dependency * feat(gateway): add servicesJsonRoute option to control documentation exposure * refactor: rename servicesJsonRoute to enableServicesEndpoint for clarity
1 parent 6b4ec6c commit b6d85ee

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

docs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ module.exports.handler = serverless(service)
138138
// - If it returns `null`, no proxy will be used and the default factory will be skipped entirely.
139139
// Default: the built-in proxy factory from `fast-gateway`
140140
proxyFactory: ({ proxyType, opts, route }) => {...}
141+
// Optional toggle for exposing minimal documentation of registered services at `GET /services.json`
142+
// Default value: true
143+
enableServicesEndpoint: true
141144

142145
// HTTP proxy
143146
routes: [{
@@ -214,6 +217,8 @@ For developers reference, default hooks implementation are located in `lib/defau
214217

215218
Since version `1.3.5` the gateway exposes minimal documentation about registered services at: `GET /services.json`
216219

220+
Since version `4.2.0`, the `/services.json` route can be disabled by setting `enableServicesEndpoint: false` in the gateway options.
221+
217222
Example output:
218223

219224
```json

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ declare namespace fastgateway {
7676
pathRegex?: string
7777
timeout?: number
7878
targetOverride?: string
79+
enableServicesEndpoint?: boolean
7980
routes: (Route | WebSocketRoute)[]
8081
}
8182
}

index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const DEFAULT_METHODS = require('restana/libs/methods').filter(
1010
(method) => method !== 'all'
1111
)
1212
const NOOP = (req, res) => {}
13-
const send = require('@polka/send-type')
1413
const PROXY_TYPES = ['http', 'lambda']
1514
const registerWebSocketRoutes = require('./lib/ws-proxy')
1615

@@ -29,7 +28,8 @@ const gateway = (opts) => {
2928
opts = Object.assign(
3029
{
3130
middlewares: [],
32-
pathRegex: '/*'
31+
pathRegex: '/*',
32+
enableServicesEndpoint: true
3333
},
3434
opts
3535
)
@@ -46,9 +46,13 @@ const gateway = (opts) => {
4646
prefix: route.prefix,
4747
docs: route.docs
4848
}))
49-
router.get('/services.json', (req, res) => {
50-
send(res, 200, services)
51-
})
49+
if (opts.enableServicesEndpoint) {
50+
router.get('/services.json', (req, res) => {
51+
res.statusCode = 200
52+
res.setHeader('Content-Type', 'application/json')
53+
res.end(JSON.stringify(services))
54+
})
55+
}
5256

5357
// processing websocket routes
5458
const wsRoutes = opts.routes.filter(

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"LICENSE"
4343
],
4444
"devDependencies": {
45-
"@polka/send-type": "^0.5.2",
4645
"@types/node": "^22.13.11",
4746
"@types/express": "^5.0.0",
4847
"artillery": "^2.0.21",

0 commit comments

Comments
 (0)