@defra/lis-hubs-infra-core 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/proxy-plugin.js +3 -1
- package/src/proxy-plugin.test.js +34 -1
package/package.json
CHANGED
package/src/proxy-plugin.js
CHANGED
|
@@ -34,7 +34,9 @@ export function createProxyPlugin({ hubId, environment }) {
|
|
|
34
34
|
xforward: true,
|
|
35
35
|
mapUri(request) {
|
|
36
36
|
const subPath = request.params.path ?? ''
|
|
37
|
-
const uri =
|
|
37
|
+
const uri =
|
|
38
|
+
(subPath ? `${baseUri}/${subPath}` : baseUri) +
|
|
39
|
+
request.url.search
|
|
38
40
|
|
|
39
41
|
return {
|
|
40
42
|
uri,
|
package/src/proxy-plugin.test.js
CHANGED
|
@@ -41,6 +41,7 @@ describe('createProxyPlugin()', () => {
|
|
|
41
41
|
expect(
|
|
42
42
|
route.handler.proxy.mapUri({
|
|
43
43
|
params: { path: 'summary-data' },
|
|
44
|
+
url: new URL('http://hub.test/cattle/summary-data'),
|
|
44
45
|
headers: {
|
|
45
46
|
authorization: 'Bearer hub-service-token',
|
|
46
47
|
cookie: 'session=abc'
|
|
@@ -54,7 +55,13 @@ describe('createProxyPlugin()', () => {
|
|
|
54
55
|
cookie: 'session=abc'
|
|
55
56
|
}
|
|
56
57
|
})
|
|
57
|
-
expect(
|
|
58
|
+
expect(
|
|
59
|
+
route.handler.proxy.mapUri({
|
|
60
|
+
params: {},
|
|
61
|
+
url: new URL('http://hub.test/cattle'),
|
|
62
|
+
headers: {}
|
|
63
|
+
})
|
|
64
|
+
).toEqual({
|
|
58
65
|
uri: expectedBaseUri,
|
|
59
66
|
headers: {
|
|
60
67
|
'x-forwarded-prefix': '/cattle'
|
|
@@ -62,6 +69,32 @@ describe('createProxyPlugin()', () => {
|
|
|
62
69
|
})
|
|
63
70
|
})
|
|
64
71
|
|
|
72
|
+
test('forwards the incoming query string to the proxied service', async () => {
|
|
73
|
+
// Arrange
|
|
74
|
+
const server = { route: vi.fn(), register: vi.fn() }
|
|
75
|
+
const proxy = createProxyPlugin({
|
|
76
|
+
hubId: 'back-office',
|
|
77
|
+
environment: 'local'
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
// Act
|
|
81
|
+
await proxy.plugin.register(server)
|
|
82
|
+
|
|
83
|
+
// Assert
|
|
84
|
+
const route = server.route.mock.calls[0][0]
|
|
85
|
+
expect(
|
|
86
|
+
route.handler.proxy.mapUri({
|
|
87
|
+
params: { path: 'animals' },
|
|
88
|
+
url: new URL(
|
|
89
|
+
'http://hub.test/cattle/animals?sort=sex&direction=asc&page=1'
|
|
90
|
+
),
|
|
91
|
+
headers: {}
|
|
92
|
+
})
|
|
93
|
+
).toMatchObject({
|
|
94
|
+
uri: 'http://localhost:3222/animals?sort=sex&direction=asc&page=1'
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
65
98
|
test('rejects an unsupported environment', async () => {
|
|
66
99
|
// Arrange
|
|
67
100
|
const server = { route: vi.fn(), register: vi.fn() }
|