Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ declare namespace fastgateway {
pathRegex?: string
timeout?: number
targetOverride?: string
enableServicesEndpoint?: boolean
routes: (Route | WebSocketRoute)[]
}
}
Expand Down
14 changes: 9 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -29,7 +28,8 @@ const gateway = (opts) => {
opts = Object.assign(
{
middlewares: [],
pathRegex: '/*'
pathRegex: '/*',
enableServicesEndpoint: true
},
opts
)
Expand All @@ -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(
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down