Skip to content

Commit d70a6aa

Browse files
authored
Introducing disableQsOverwrite route configuration (#82)
* introducing disableQsOverride route configuration
1 parent 9f6291f commit d70a6aa

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

docs/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ module.exports.handler = serverless(service)
136136
// Optional service requests timeout value (given in milliseconds). Default value: '0' (DISABLED)
137137
// This setting apply only when proxyType = 'http'
138138
timeout: 0,
139-
// route prefix
139+
// Route prefix
140140
prefix: '/public',
141+
// Uses the raw request query string value instead of req.query. Default value: false
142+
disableQsOverwrite: true,
141143
// Optional documentation configuration (unrestricted schema)
142144
docs: {
143145
name: 'Public Service',

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ declare namespace fastgateway {
3131
middlewares?: Function[];
3232
urlRewrite?: Function;
3333
hooks?: Hooks;
34+
disableQsOverwrite?: boolean;
3435
}
3536

3637
interface WebSocketRoute {

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const handler = (route, proxy, proxyHandler) => async (req, res, next) => {
118118
request: {
119119
timeout: req.timeout || route.timeout
120120
},
121-
queryString: req.query
121+
queryString: route.disableQsOverwrite ? null : req.query
122122
}, route.hooks)
123123

124124
proxyHandler(req, res, req.url, proxy, proxyOpts)

test/config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ module.exports = async () => {
8585
}
8686
}
8787
},
88+
{
89+
pathRegex: '',
90+
prefix: '/qs-no-overwrite',
91+
disableQsOverwrite: true,
92+
prefixRewrite: '/qs-no-overwrite',
93+
target: 'http://localhost:3000',
94+
methods: ['GET'],
95+
hooks: {
96+
onRequest: (req) => {
97+
req.query.name = 'fast-gateway'
98+
}
99+
}
100+
},
88101
{
89102
pathRegex: '',
90103
prefix: '/qs2',

test/smoke.test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('API Gateway', () => {
5555
remote.post('/endpoint-proxy-methods', (req, res) => res.send({
5656
name: 'endpoint-proxy-methods'
5757
}))
58-
remote.get('/qs', (req, res) => {
58+
remote.get(['/qs-no-overwrite', '/qs'], (req, res) => {
5959
res.send(req.query)
6060
})
6161

@@ -318,6 +318,16 @@ describe('API Gateway', () => {
318318
})
319319
})
320320

321+
it('(Should NOT overwrite query string using req.query) GET /qs-no-overwrite - 200', async () => {
322+
await request(gateway)
323+
.get('/qs-no-overwrite?name=nodejs&category=js')
324+
.expect(200)
325+
.then((response) => {
326+
expect(response.body.name).to.equal('nodejs')
327+
expect(response.body.category).to.equal('js')
328+
})
329+
})
330+
321331
it('(Should overwrite query string using queryString option) GET /qs2 - 200', async () => {
322332
await request(gateway)
323333
.get('/qs2?name=fast-gateway')

0 commit comments

Comments
 (0)