@furystack/rest-service 13.0.0 → 14.0.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.
Files changed (224) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +47 -28
  3. package/esm/actions/get-current-user.spec.js +10 -6
  4. package/esm/actions/get-current-user.spec.js.map +1 -1
  5. package/esm/actions/is-authenticated.spec.js +10 -6
  6. package/esm/actions/is-authenticated.spec.js.map +1 -1
  7. package/esm/actions/logout-action.spec.js +11 -9
  8. package/esm/actions/logout-action.spec.js.map +1 -1
  9. package/esm/actions/logout.js +1 -1
  10. package/esm/actions/logout.js.map +1 -1
  11. package/esm/actions/password-login-action.js +1 -1
  12. package/esm/actions/password-login-action.js.map +1 -1
  13. package/esm/actions/password-login-action.spec.js +23 -28
  14. package/esm/actions/password-login-action.spec.js.map +1 -1
  15. package/esm/authenticate.js +1 -1
  16. package/esm/authenticate.js.map +1 -1
  17. package/esm/authenticate.spec.js +41 -33
  18. package/esm/authenticate.spec.js.map +1 -1
  19. package/esm/authorize.spec.js +34 -29
  20. package/esm/authorize.spec.js.map +1 -1
  21. package/esm/endpoint-generators/create-delete-endpoint.d.ts +6 -11
  22. package/esm/endpoint-generators/create-delete-endpoint.d.ts.map +1 -1
  23. package/esm/endpoint-generators/create-delete-endpoint.js +7 -11
  24. package/esm/endpoint-generators/create-delete-endpoint.js.map +1 -1
  25. package/esm/endpoint-generators/create-delete-endpoint.spec.js +14 -21
  26. package/esm/endpoint-generators/create-delete-endpoint.spec.js.map +1 -1
  27. package/esm/endpoint-generators/create-get-collection-endpoint.d.ts +11 -11
  28. package/esm/endpoint-generators/create-get-collection-endpoint.d.ts.map +1 -1
  29. package/esm/endpoint-generators/create-get-collection-endpoint.js +13 -12
  30. package/esm/endpoint-generators/create-get-collection-endpoint.js.map +1 -1
  31. package/esm/endpoint-generators/create-get-collection-endpoint.spec.js +43 -70
  32. package/esm/endpoint-generators/create-get-collection-endpoint.spec.js.map +1 -1
  33. package/esm/endpoint-generators/create-get-entity-endpoint.d.ts +6 -11
  34. package/esm/endpoint-generators/create-get-entity-endpoint.d.ts.map +1 -1
  35. package/esm/endpoint-generators/create-get-entity-endpoint.js +7 -11
  36. package/esm/endpoint-generators/create-get-entity-endpoint.js.map +1 -1
  37. package/esm/endpoint-generators/create-get-entity-endpoint.spec.js +16 -33
  38. package/esm/endpoint-generators/create-get-entity-endpoint.spec.js.map +1 -1
  39. package/esm/endpoint-generators/create-get-openapi-document-action.d.ts +1 -1
  40. package/esm/endpoint-generators/create-get-openapi-document-action.d.ts.map +1 -1
  41. package/esm/endpoint-generators/create-get-openapi-document-action.js +1 -1
  42. package/esm/endpoint-generators/create-get-openapi-document-action.js.map +1 -1
  43. package/esm/endpoint-generators/create-get-schema-action.d.ts +1 -1
  44. package/esm/endpoint-generators/create-get-schema-action.d.ts.map +1 -1
  45. package/esm/endpoint-generators/create-get-schema-action.js.map +1 -1
  46. package/esm/endpoint-generators/create-patch-endpoint.d.ts +7 -13
  47. package/esm/endpoint-generators/create-patch-endpoint.d.ts.map +1 -1
  48. package/esm/endpoint-generators/create-patch-endpoint.js +8 -13
  49. package/esm/endpoint-generators/create-patch-endpoint.js.map +1 -1
  50. package/esm/endpoint-generators/create-patch-endpoint.spec.js +10 -17
  51. package/esm/endpoint-generators/create-patch-endpoint.spec.js.map +1 -1
  52. package/esm/endpoint-generators/create-post-endpoint.d.ts +7 -13
  53. package/esm/endpoint-generators/create-post-endpoint.d.ts.map +1 -1
  54. package/esm/endpoint-generators/create-post-endpoint.js +8 -13
  55. package/esm/endpoint-generators/create-post-endpoint.js.map +1 -1
  56. package/esm/endpoint-generators/create-post-endpoint.spec.js +41 -14
  57. package/esm/endpoint-generators/create-post-endpoint.spec.js.map +1 -1
  58. package/esm/endpoint-generators/utils.d.ts +17 -2
  59. package/esm/endpoint-generators/utils.d.ts.map +1 -1
  60. package/esm/endpoint-generators/utils.js +33 -20
  61. package/esm/endpoint-generators/utils.js.map +1 -1
  62. package/esm/get-schema-from-api.d.ts +1 -1
  63. package/esm/get-schema-from-api.d.ts.map +1 -1
  64. package/esm/get-schema-from-api.spec.js.map +1 -1
  65. package/esm/helpers.d.ts +53 -87
  66. package/esm/helpers.d.ts.map +1 -1
  67. package/esm/helpers.js +91 -92
  68. package/esm/helpers.js.map +1 -1
  69. package/esm/helpers.spec.d.ts +2 -1
  70. package/esm/helpers.spec.d.ts.map +1 -1
  71. package/esm/helpers.spec.js +41 -38
  72. package/esm/helpers.spec.js.map +1 -1
  73. package/esm/http-authentication-settings.d.ts +35 -12
  74. package/esm/http-authentication-settings.d.ts.map +1 -1
  75. package/esm/http-authentication-settings.js +21 -29
  76. package/esm/http-authentication-settings.js.map +1 -1
  77. package/esm/http-server-pool.d.ts +64 -0
  78. package/esm/http-server-pool.d.ts.map +1 -0
  79. package/esm/http-server-pool.js +95 -0
  80. package/esm/http-server-pool.js.map +1 -0
  81. package/esm/http-server-pool.spec.d.ts +2 -0
  82. package/esm/http-server-pool.spec.d.ts.map +1 -0
  83. package/esm/http-server-pool.spec.js +193 -0
  84. package/esm/http-server-pool.spec.js.map +1 -0
  85. package/esm/http-user-context.d.ts +31 -44
  86. package/esm/http-user-context.d.ts.map +1 -1
  87. package/esm/http-user-context.js +76 -95
  88. package/esm/http-user-context.js.map +1 -1
  89. package/esm/http-user-context.spec.d.ts +8 -2
  90. package/esm/http-user-context.spec.d.ts.map +1 -1
  91. package/esm/http-user-context.spec.js +189 -337
  92. package/esm/http-user-context.spec.js.map +1 -1
  93. package/esm/index.d.ts +6 -4
  94. package/esm/index.d.ts.map +1 -1
  95. package/esm/index.js +6 -4
  96. package/esm/index.js.map +1 -1
  97. package/esm/login-response-strategy.d.ts +11 -10
  98. package/esm/login-response-strategy.d.ts.map +1 -1
  99. package/esm/login-response-strategy.js +7 -6
  100. package/esm/login-response-strategy.js.map +1 -1
  101. package/esm/login-response-strategy.spec.js +25 -29
  102. package/esm/login-response-strategy.spec.js.map +1 -1
  103. package/esm/proxy-manager.spec.js +152 -176
  104. package/esm/proxy-manager.spec.js.map +1 -1
  105. package/esm/proxy-runtime.d.ts +27 -0
  106. package/esm/proxy-runtime.d.ts.map +1 -0
  107. package/esm/proxy-runtime.js +45 -0
  108. package/esm/proxy-runtime.js.map +1 -0
  109. package/esm/proxy-runtime.spec.d.ts +2 -0
  110. package/esm/proxy-runtime.spec.d.ts.map +1 -0
  111. package/esm/proxy-runtime.spec.js +39 -0
  112. package/esm/proxy-runtime.spec.js.map +1 -0
  113. package/esm/rest-api-runtime.d.ts +76 -0
  114. package/esm/rest-api-runtime.d.ts.map +1 -0
  115. package/esm/rest-api-runtime.js +131 -0
  116. package/esm/rest-api-runtime.js.map +1 -0
  117. package/esm/rest-api-runtime.spec.d.ts +2 -0
  118. package/esm/rest-api-runtime.spec.d.ts.map +1 -0
  119. package/esm/rest-api-runtime.spec.js +58 -0
  120. package/esm/rest-api-runtime.spec.js.map +1 -0
  121. package/esm/rest-service.integration.spec.d.ts +1 -1
  122. package/esm/rest-service.integration.spec.d.ts.map +1 -1
  123. package/esm/rest-service.integration.spec.js +57 -80
  124. package/esm/rest-service.integration.spec.js.map +1 -1
  125. package/esm/rest.integration.test.js +26 -84
  126. package/esm/rest.integration.test.js.map +1 -1
  127. package/esm/server-telemetry.d.ts +57 -0
  128. package/esm/server-telemetry.d.ts.map +1 -0
  129. package/esm/server-telemetry.js +26 -0
  130. package/esm/server-telemetry.js.map +1 -0
  131. package/esm/server-telemetry.spec.d.ts +2 -0
  132. package/esm/server-telemetry.spec.d.ts.map +1 -0
  133. package/esm/server-telemetry.spec.js +52 -0
  134. package/esm/server-telemetry.spec.js.map +1 -0
  135. package/esm/static-server-manager.spec.js +60 -125
  136. package/esm/static-server-manager.spec.js.map +1 -1
  137. package/esm/static-site-runtime.d.ts +21 -0
  138. package/esm/static-site-runtime.d.ts.map +1 -0
  139. package/esm/static-site-runtime.js +48 -0
  140. package/esm/static-site-runtime.js.map +1 -0
  141. package/esm/static-site-runtime.spec.d.ts +2 -0
  142. package/esm/static-site-runtime.spec.d.ts.map +1 -0
  143. package/esm/static-site-runtime.spec.js +30 -0
  144. package/esm/static-site-runtime.spec.js.map +1 -0
  145. package/esm/user-store.d.ts +39 -0
  146. package/esm/user-store.d.ts.map +1 -0
  147. package/esm/user-store.js +62 -0
  148. package/esm/user-store.js.map +1 -0
  149. package/esm/user-store.spec.d.ts +2 -0
  150. package/esm/user-store.spec.d.ts.map +1 -0
  151. package/esm/user-store.spec.js +72 -0
  152. package/esm/user-store.spec.js.map +1 -0
  153. package/esm/validate.integration.spec.js +26 -28
  154. package/esm/validate.integration.spec.js.map +1 -1
  155. package/package.json +8 -8
  156. package/src/actions/get-current-user.spec.ts +11 -10
  157. package/src/actions/is-authenticated.spec.ts +12 -7
  158. package/src/actions/logout-action.spec.ts +12 -12
  159. package/src/actions/logout.ts +1 -1
  160. package/src/actions/password-login-action.spec.ts +30 -30
  161. package/src/actions/password-login-action.ts +1 -1
  162. package/src/authenticate.spec.ts +45 -51
  163. package/src/authenticate.ts +1 -1
  164. package/src/authorize.spec.ts +37 -39
  165. package/src/endpoint-generators/create-delete-endpoint.spec.ts +16 -24
  166. package/src/endpoint-generators/create-delete-endpoint.ts +11 -17
  167. package/src/endpoint-generators/create-get-collection-endpoint.spec.ts +45 -78
  168. package/src/endpoint-generators/create-get-collection-endpoint.ts +17 -19
  169. package/src/endpoint-generators/create-get-entity-endpoint.spec.ts +17 -33
  170. package/src/endpoint-generators/create-get-entity-endpoint.ts +11 -17
  171. package/src/endpoint-generators/create-get-openapi-document-action.ts +2 -2
  172. package/src/endpoint-generators/create-get-schema-action.ts +1 -1
  173. package/src/endpoint-generators/create-patch-endpoint.spec.ts +11 -18
  174. package/src/endpoint-generators/create-patch-endpoint.ts +12 -23
  175. package/src/endpoint-generators/create-post-endpoint.spec.ts +45 -14
  176. package/src/endpoint-generators/create-post-endpoint.ts +13 -23
  177. package/src/endpoint-generators/utils.ts +36 -28
  178. package/src/get-schema-from-api.spec.ts +1 -1
  179. package/src/get-schema-from-api.ts +1 -1
  180. package/src/helpers.spec.ts +51 -41
  181. package/src/helpers.ts +140 -109
  182. package/src/http-authentication-settings.ts +51 -25
  183. package/src/http-server-pool.spec.ts +220 -0
  184. package/src/http-server-pool.ts +169 -0
  185. package/src/http-user-context.spec.ts +203 -383
  186. package/src/http-user-context.ts +114 -91
  187. package/src/index.ts +6 -4
  188. package/src/login-response-strategy.spec.ts +32 -31
  189. package/src/login-response-strategy.ts +13 -12
  190. package/src/proxy-manager.spec.ts +152 -182
  191. package/src/proxy-runtime.spec.ts +50 -0
  192. package/src/proxy-runtime.ts +75 -0
  193. package/src/rest-api-runtime.spec.ts +77 -0
  194. package/src/rest-api-runtime.ts +204 -0
  195. package/src/rest-service.integration.spec.ts +65 -85
  196. package/src/rest.integration.test.ts +27 -87
  197. package/src/server-telemetry.spec.ts +56 -0
  198. package/src/server-telemetry.ts +51 -0
  199. package/src/static-server-manager.spec.ts +63 -151
  200. package/src/static-site-runtime.spec.ts +39 -0
  201. package/src/static-site-runtime.ts +75 -0
  202. package/src/user-store.spec.ts +86 -0
  203. package/src/user-store.ts +68 -0
  204. package/src/validate.integration.spec.ts +39 -35
  205. package/esm/api-manager.d.ts +0 -104
  206. package/esm/api-manager.d.ts.map +0 -1
  207. package/esm/api-manager.js +0 -179
  208. package/esm/api-manager.js.map +0 -1
  209. package/esm/proxy-manager.d.ts +0 -53
  210. package/esm/proxy-manager.d.ts.map +0 -1
  211. package/esm/proxy-manager.js +0 -84
  212. package/esm/proxy-manager.js.map +0 -1
  213. package/esm/server-manager.d.ts +0 -48
  214. package/esm/server-manager.d.ts.map +0 -1
  215. package/esm/server-manager.js +0 -100
  216. package/esm/server-manager.js.map +0 -1
  217. package/esm/static-server-manager.d.ts +0 -19
  218. package/esm/static-server-manager.d.ts.map +0 -1
  219. package/esm/static-server-manager.js +0 -65
  220. package/esm/static-server-manager.js.map +0 -1
  221. package/src/api-manager.ts +0 -304
  222. package/src/proxy-manager.ts +0 -102
  223. package/src/server-manager.ts +0 -135
  224. package/src/static-server-manager.ts +0 -90
@@ -1,5 +1,5 @@
1
1
  import { getPort } from '@furystack/core/port-generator'
2
- import { Injector } from '@furystack/inject'
2
+ import { createInjector } from '@furystack/inject'
3
3
  import { usingAsync } from '@furystack/utils'
4
4
  import { mkdirSync, writeFileSync } from 'fs'
5
5
  import type { IncomingMessage, OutgoingHttpHeaders, Server, ServerResponse } from 'http'
@@ -9,8 +9,9 @@ import { join } from 'path'
9
9
  import { beforeAll, describe, expect, it } from 'vitest'
10
10
  import type { RawData } from 'ws'
11
11
  import { WebSocket, WebSocketServer } from 'ws'
12
- import { ProxyManager } from './proxy-manager.js'
13
- import { StaticServerManager } from './static-server-manager.js'
12
+ import { useProxy } from './helpers.js'
13
+ import { ServerTelemetryToken } from './server-telemetry.js'
14
+ import { useStaticFiles } from './helpers.js'
14
15
 
15
16
  describe('ProxyManager', () => {
16
17
  // Create a temporary directory for test files
@@ -64,10 +65,7 @@ describe('ProxyManager', () => {
64
65
 
65
66
  describe('Basic proxy functionality', () => {
66
67
  it('Should proxy requests from source URL to target URL', async () => {
67
- await usingAsync(new Injector(), async (injector) => {
68
- const proxyManager = injector.getInstance(ProxyManager)
69
- const staticServerManager = injector.getInstance(StaticServerManager)
70
-
68
+ await usingAsync(createInjector(), async (injector) => {
71
69
  const proxyPort = getPort()
72
70
  const targetPort = getPort()
73
71
 
@@ -83,14 +81,11 @@ describe('ProxyManager', () => {
83
81
  )
84
82
 
85
83
  // Set up target server (static file server) - serve files from testDir
86
- await staticServerManager.addStaticSite({
87
- baseUrl: '/',
88
- path: testDir,
89
- port: targetPort,
90
- })
84
+ await useStaticFiles({ injector, baseUrl: '/', path: testDir, port: targetPort })
91
85
 
92
86
  // Set up proxy server
93
- await proxyManager.addProxy({
87
+ await useProxy({
88
+ injector,
94
89
  sourceBaseUrl: '/old',
95
90
  targetBaseUrl: `http://localhost:${targetPort}`,
96
91
  pathRewrite: (path) => path.replace('/path', ''),
@@ -109,8 +104,7 @@ describe('ProxyManager', () => {
109
104
  })
110
105
 
111
106
  it('Should preserve query strings when proxying', async () => {
112
- await usingAsync(new Injector(), async (injector) => {
113
- const proxyManager = injector.getInstance(ProxyManager)
107
+ await usingAsync(createInjector(), async (injector) => {
114
108
  const targetPort = getPort()
115
109
  const proxyPort = getPort()
116
110
 
@@ -125,7 +119,8 @@ describe('ProxyManager', () => {
125
119
  })
126
120
 
127
121
  try {
128
- await proxyManager.addProxy({
122
+ await useProxy({
123
+ injector,
129
124
  sourceBaseUrl: '/api',
130
125
  targetBaseUrl: `http://localhost:${targetPort}`,
131
126
  sourcePort: proxyPort,
@@ -143,10 +138,7 @@ describe('ProxyManager', () => {
143
138
  })
144
139
 
145
140
  it('Should handle header transformation', async () => {
146
- await usingAsync(new Injector(), async (injector) => {
147
- const proxyManager = injector.getInstance(ProxyManager)
148
- const staticServerManager = injector.getInstance(StaticServerManager)
149
-
141
+ await usingAsync(createInjector(), async (injector) => {
150
142
  const proxyPort = getPort()
151
143
  const targetPort = getPort()
152
144
 
@@ -161,14 +153,11 @@ describe('ProxyManager', () => {
161
153
  )
162
154
 
163
155
  // Set up target server
164
- await staticServerManager.addStaticSite({
165
- baseUrl: '/',
166
- path: testDir,
167
- port: targetPort,
168
- })
156
+ await useStaticFiles({ injector, baseUrl: '/', path: testDir, port: targetPort })
169
157
 
170
158
  // Set up proxy server with header transformation
171
- await proxyManager.addProxy({
159
+ await useProxy({
160
+ injector,
172
161
  sourceBaseUrl: '/old',
173
162
  targetBaseUrl: `http://localhost:${targetPort}`,
174
163
  pathRewrite: (path) => path.replace('/path', ''),
@@ -193,10 +182,7 @@ describe('ProxyManager', () => {
193
182
  })
194
183
 
195
184
  it('Should handle cookie transformation', async () => {
196
- await usingAsync(new Injector(), async (injector) => {
197
- const proxyManager = injector.getInstance(ProxyManager)
198
- const staticServerManager = injector.getInstance(StaticServerManager)
199
-
185
+ await usingAsync(createInjector(), async (injector) => {
200
186
  const proxyPort = getPort()
201
187
  const targetPort = getPort()
202
188
 
@@ -211,14 +197,11 @@ describe('ProxyManager', () => {
211
197
  )
212
198
 
213
199
  // Set up target server
214
- await staticServerManager.addStaticSite({
215
- baseUrl: '/',
216
- path: testDir,
217
- port: targetPort,
218
- })
200
+ await useStaticFiles({ injector, baseUrl: '/', path: testDir, port: targetPort })
219
201
 
220
202
  // Set up proxy server with cookie transformation
221
- await proxyManager.addProxy({
203
+ await useProxy({
204
+ injector,
222
205
  sourceBaseUrl: '/old',
223
206
  targetBaseUrl: `http://localhost:${targetPort}`,
224
207
  pathRewrite: (path) => path.replace('/path', ''),
@@ -239,8 +222,7 @@ describe('ProxyManager', () => {
239
222
  })
240
223
 
241
224
  it('Should handle POST requests with JSON body', async () => {
242
- await usingAsync(new Injector(), async (injector) => {
243
- const proxyManager = injector.getInstance(ProxyManager)
225
+ await usingAsync(createInjector(), async (injector) => {
244
226
  const targetPort = getPort()
245
227
  const proxyPort = getPort()
246
228
 
@@ -262,7 +244,8 @@ describe('ProxyManager', () => {
262
244
  })
263
245
 
264
246
  try {
265
- await proxyManager.addProxy({
247
+ await useProxy({
248
+ injector,
266
249
  sourceBaseUrl: '/api',
267
250
  targetBaseUrl: `http://localhost:${targetPort}`,
268
251
  sourcePort: proxyPort,
@@ -286,8 +269,7 @@ describe('ProxyManager', () => {
286
269
  })
287
270
 
288
271
  it('Should handle response cookies transformation', async () => {
289
- await usingAsync(new Injector(), async (injector) => {
290
- const proxyManager = injector.getInstance(ProxyManager)
272
+ await usingAsync(createInjector(), async (injector) => {
291
273
  const targetPort = getPort()
292
274
  const proxyPort = getPort()
293
275
 
@@ -305,7 +287,8 @@ describe('ProxyManager', () => {
305
287
  })
306
288
 
307
289
  try {
308
- await proxyManager.addProxy({
290
+ await useProxy({
291
+ injector,
309
292
  sourceBaseUrl: '/api',
310
293
  targetBaseUrl: `http://localhost:${targetPort}`,
311
294
  sourcePort: proxyPort,
@@ -328,10 +311,7 @@ describe('ProxyManager', () => {
328
311
  })
329
312
 
330
313
  it('Should not match requests outside source base URL', async () => {
331
- await usingAsync(new Injector(), async (injector) => {
332
- const proxyManager = injector.getInstance(ProxyManager)
333
- const staticServerManager = injector.getInstance(StaticServerManager)
334
-
314
+ await usingAsync(createInjector(), async (injector) => {
335
315
  const proxyPort = getPort()
336
316
  const targetPort = getPort()
337
317
 
@@ -340,14 +320,11 @@ describe('ProxyManager', () => {
340
320
  writeFileSync(testFile, JSON.stringify({ message: 'test' }))
341
321
 
342
322
  // Set up target server
343
- await staticServerManager.addStaticSite({
344
- baseUrl: '/',
345
- path: testDir,
346
- port: targetPort,
347
- })
323
+ await useStaticFiles({ injector, baseUrl: '/', path: testDir, port: targetPort })
348
324
 
349
325
  // Set up proxy server
350
- await proxyManager.addProxy({
326
+ await useProxy({
327
+ injector,
351
328
  sourceBaseUrl: '/old',
352
329
  targetBaseUrl: `http://localhost:${targetPort}`,
353
330
  pathRewrite: (path) => path.replace('/path', ''),
@@ -367,10 +344,7 @@ describe('ProxyManager', () => {
367
344
  })
368
345
 
369
346
  it('Should handle exact URL matches', async () => {
370
- await usingAsync(new Injector(), async (injector) => {
371
- const proxyManager = injector.getInstance(ProxyManager)
372
- const staticServerManager = injector.getInstance(StaticServerManager)
373
-
347
+ await usingAsync(createInjector(), async (injector) => {
374
348
  const proxyPort = getPort()
375
349
  const targetPort = getPort()
376
350
 
@@ -385,14 +359,11 @@ describe('ProxyManager', () => {
385
359
  )
386
360
 
387
361
  // Set up target server
388
- await staticServerManager.addStaticSite({
389
- baseUrl: '/',
390
- path: testDir,
391
- port: targetPort,
392
- })
362
+ await useStaticFiles({ injector, baseUrl: '/', path: testDir, port: targetPort })
393
363
 
394
364
  // Set up proxy server
395
- await proxyManager.addProxy({
365
+ await useProxy({
366
+ injector,
396
367
  sourceBaseUrl: '/exact',
397
368
  targetBaseUrl: `http://localhost:${targetPort}`,
398
369
  pathRewrite: (path) => path, // Keep the path as-is
@@ -409,13 +380,13 @@ describe('ProxyManager', () => {
409
380
  })
410
381
 
411
382
  it('Should handle server errors gracefully', async () => {
412
- await usingAsync(new Injector(), async (injector) => {
413
- const proxyManager = injector.getInstance(ProxyManager)
383
+ await usingAsync(createInjector(), async (injector) => {
414
384
  const proxyPort = getPort()
415
385
  const unavailablePort = getPort() // Get a valid port number that doesn't have a server
416
386
 
417
387
  // Set up proxy to non-existent target
418
- await proxyManager.addProxy({
388
+ await useProxy({
389
+ injector,
419
390
  sourceBaseUrl: '/api',
420
391
  targetBaseUrl: `http://localhost:${unavailablePort}`,
421
392
  sourcePort: proxyPort,
@@ -428,19 +399,19 @@ describe('ProxyManager', () => {
428
399
  })
429
400
 
430
401
  it('Should emit onProxyFailed event on error', async () => {
431
- await usingAsync(new Injector(), async (injector) => {
432
- const proxyManager = injector.getInstance(ProxyManager)
402
+ await usingAsync(createInjector(), async (injector) => {
433
403
  const proxyPort = getPort()
434
404
  const unavailablePort = getPort()
435
405
 
436
406
  let failedEvent: { from: string; to: string; error: unknown } | undefined
437
407
 
438
- proxyManager.subscribe('onProxyFailed', (event) => {
408
+ injector.get(ServerTelemetryToken).subscribe('onProxyFailed', (event) => {
439
409
  failedEvent = event
440
410
  })
441
411
 
442
412
  // Set up proxy to non-existent target
443
- await proxyManager.addProxy({
413
+ await useProxy({
414
+ injector,
444
415
  sourceBaseUrl: '/api',
445
416
  targetBaseUrl: `http://localhost:${unavailablePort}`,
446
417
  sourcePort: proxyPort,
@@ -455,11 +426,10 @@ describe('ProxyManager', () => {
455
426
  })
456
427
 
457
428
  it('Should validate targetBaseUrl on addProxy', async () => {
458
- await usingAsync(new Injector(), async (injector) => {
459
- const proxyManager = injector.getInstance(ProxyManager)
460
-
429
+ await usingAsync(createInjector(), async (injector) => {
461
430
  await expect(
462
- proxyManager.addProxy({
431
+ useProxy({
432
+ injector,
463
433
  sourceBaseUrl: '/api',
464
434
  targetBaseUrl: 'not-a-valid-url',
465
435
  sourcePort: getPort(),
@@ -469,8 +439,7 @@ describe('ProxyManager', () => {
469
439
  })
470
440
 
471
441
  it('Should filter hop-by-hop headers', async () => {
472
- await usingAsync(new Injector(), async (injector) => {
473
- const proxyManager = injector.getInstance(ProxyManager)
442
+ await usingAsync(createInjector(), async (injector) => {
474
443
  const targetPort = getPort()
475
444
  const proxyPort = getPort()
476
445
 
@@ -488,7 +457,8 @@ describe('ProxyManager', () => {
488
457
  })
489
458
 
490
459
  try {
491
- await proxyManager.addProxy({
460
+ await useProxy({
461
+ injector,
492
462
  sourceBaseUrl: '/api',
493
463
  targetBaseUrl: `http://localhost:${targetPort}`,
494
464
  sourcePort: proxyPort,
@@ -518,8 +488,7 @@ describe('ProxyManager', () => {
518
488
  })
519
489
 
520
490
  it('Should preserve multiple Set-Cookie headers from target', async () => {
521
- await usingAsync(new Injector(), async (injector) => {
522
- const proxyManager = injector.getInstance(ProxyManager)
491
+ await usingAsync(createInjector(), async (injector) => {
523
492
  const targetPort = getPort()
524
493
  const proxyPort = getPort()
525
494
 
@@ -536,7 +505,8 @@ describe('ProxyManager', () => {
536
505
  })
537
506
 
538
507
  try {
539
- await proxyManager.addProxy({
508
+ await useProxy({
509
+ injector,
540
510
  sourceBaseUrl: '/api',
541
511
  targetBaseUrl: `http://localhost:${targetPort}`,
542
512
  sourcePort: proxyPort,
@@ -565,8 +535,7 @@ describe('ProxyManager', () => {
565
535
  })
566
536
 
567
537
  it('Should add X-Forwarded headers to target request', async () => {
568
- await usingAsync(new Injector(), async (injector) => {
569
- const proxyManager = injector.getInstance(ProxyManager)
538
+ await usingAsync(createInjector(), async (injector) => {
570
539
  const targetPort = getPort()
571
540
  const proxyPort = getPort()
572
541
 
@@ -582,7 +551,8 @@ describe('ProxyManager', () => {
582
551
  })
583
552
 
584
553
  try {
585
- await proxyManager.addProxy({
554
+ await useProxy({
555
+ injector,
586
556
  sourceBaseUrl: '/api',
587
557
  targetBaseUrl: `http://localhost:${targetPort}`,
588
558
  sourcePort: proxyPort,
@@ -600,8 +570,7 @@ describe('ProxyManager', () => {
600
570
  })
601
571
 
602
572
  it('Should abort upstream when client disconnects', async () => {
603
- await usingAsync(new Injector(), async (injector) => {
604
- const proxyManager = injector.getInstance(ProxyManager)
573
+ await usingAsync(createInjector(), async (injector) => {
605
574
  const targetPort = getPort()
606
575
  const proxyPort = getPort()
607
576
 
@@ -629,7 +598,8 @@ describe('ProxyManager', () => {
629
598
  })
630
599
 
631
600
  try {
632
- await proxyManager.addProxy({
601
+ await useProxy({
602
+ injector,
633
603
  sourceBaseUrl: '/api',
634
604
  targetBaseUrl: `http://localhost:${targetPort}`,
635
605
  sourcePort: proxyPort,
@@ -663,14 +633,13 @@ describe('ProxyManager', () => {
663
633
  })
664
634
 
665
635
  it('Should handle request timeout', async () => {
666
- await usingAsync(new Injector(), async (injector) => {
667
- const proxyManager = injector.getInstance(ProxyManager)
636
+ await usingAsync(createInjector(), async (injector) => {
668
637
  const targetPort = getPort()
669
638
  const proxyPort = getPort()
670
639
 
671
640
  let failedEvent: { from: string; to: string; error: unknown } | undefined
672
641
 
673
- proxyManager.subscribe('onProxyFailed', (event) => {
642
+ injector.get(ServerTelemetryToken).subscribe('onProxyFailed', (event) => {
674
643
  failedEvent = event
675
644
  })
676
645
 
@@ -688,7 +657,8 @@ describe('ProxyManager', () => {
688
657
  })
689
658
 
690
659
  try {
691
- await proxyManager.addProxy({
660
+ await useProxy({
661
+ injector,
692
662
  sourceBaseUrl: '/api',
693
663
  targetBaseUrl: `http://localhost:${targetPort}`,
694
664
  sourcePort: proxyPort,
@@ -712,8 +682,7 @@ describe('ProxyManager', () => {
712
682
  })
713
683
 
714
684
  it('Should complete successfully when response is faster than timeout', async () => {
715
- await usingAsync(new Injector(), async (injector) => {
716
- const proxyManager = injector.getInstance(ProxyManager)
685
+ await usingAsync(createInjector(), async (injector) => {
717
686
  const targetPort = getPort()
718
687
  const proxyPort = getPort()
719
688
 
@@ -728,7 +697,8 @@ describe('ProxyManager', () => {
728
697
  })
729
698
 
730
699
  try {
731
- await proxyManager.addProxy({
700
+ await useProxy({
701
+ injector,
732
702
  sourceBaseUrl: '/api',
733
703
  targetBaseUrl: `http://localhost:${targetPort}`,
734
704
  sourcePort: proxyPort,
@@ -748,8 +718,7 @@ describe('ProxyManager', () => {
748
718
  })
749
719
 
750
720
  it('Should use default timeout when not specified', async () => {
751
- await usingAsync(new Injector(), async (injector) => {
752
- const proxyManager = injector.getInstance(ProxyManager)
721
+ await usingAsync(createInjector(), async (injector) => {
753
722
  const targetPort = getPort()
754
723
  const proxyPort = getPort()
755
724
 
@@ -767,7 +736,8 @@ describe('ProxyManager', () => {
767
736
 
768
737
  try {
769
738
  // No timeout specified - should use default 30000ms
770
- await proxyManager.addProxy({
739
+ await useProxy({
740
+ injector,
771
741
  sourceBaseUrl: '/api',
772
742
  targetBaseUrl: `http://localhost:${targetPort}`,
773
743
  sourcePort: proxyPort,
@@ -789,12 +759,12 @@ describe('ProxyManager', () => {
789
759
 
790
760
  describe('Edge cases and error handling', () => {
791
761
  it('Should validate invalid protocol (non-HTTP/HTTPS)', async () => {
792
- await usingAsync(new Injector(), async (injector) => {
793
- const proxyManager = injector.getInstance(ProxyManager)
762
+ await usingAsync(createInjector(), async (injector) => {
794
763
  const proxyPort = getPort()
795
764
 
796
765
  await expect(
797
- proxyManager.addProxy({
766
+ useProxy({
767
+ injector,
798
768
  sourceBaseUrl: '/api',
799
769
  targetBaseUrl: 'ftp://example.com',
800
770
  sourcePort: proxyPort,
@@ -804,14 +774,13 @@ describe('ProxyManager', () => {
804
774
  })
805
775
 
806
776
  it('Should handle invalid target URL created by pathRewrite', async () => {
807
- await usingAsync(new Injector(), async (injector) => {
808
- const proxyManager = injector.getInstance(ProxyManager)
777
+ await usingAsync(createInjector(), async (injector) => {
809
778
  const targetPort = getPort()
810
779
  const proxyPort = getPort()
811
780
 
812
781
  let failedEvent: { from: string; to: string; error: unknown } | undefined
813
782
 
814
- proxyManager.subscribe('onProxyFailed', (event) => {
783
+ injector.get(ServerTelemetryToken).subscribe('onProxyFailed', (event) => {
815
784
  failedEvent = event
816
785
  })
817
786
 
@@ -826,7 +795,8 @@ describe('ProxyManager', () => {
826
795
  })
827
796
 
828
797
  try {
829
- await proxyManager.addProxy({
798
+ await useProxy({
799
+ injector,
830
800
  sourceBaseUrl: '/api',
831
801
  targetBaseUrl: `http://localhost:${targetPort}`,
832
802
  sourcePort: proxyPort,
@@ -853,8 +823,7 @@ describe('ProxyManager', () => {
853
823
  })
854
824
 
855
825
  it('Should handle number-type header values', async () => {
856
- await usingAsync(new Injector(), async (injector) => {
857
- const proxyManager = injector.getInstance(ProxyManager)
826
+ await usingAsync(createInjector(), async (injector) => {
858
827
  const targetPort = getPort()
859
828
  const proxyPort = getPort()
860
829
 
@@ -872,7 +841,8 @@ describe('ProxyManager', () => {
872
841
  })
873
842
 
874
843
  try {
875
- await proxyManager.addProxy({
844
+ await useProxy({
845
+ injector,
876
846
  sourceBaseUrl: '/api',
877
847
  targetBaseUrl: `http://localhost:${targetPort}`,
878
848
  sourcePort: proxyPort,
@@ -904,8 +874,7 @@ describe('ProxyManager', () => {
904
874
  })
905
875
 
906
876
  it('Should handle array-type header values', async () => {
907
- await usingAsync(new Injector(), async (injector) => {
908
- const proxyManager = injector.getInstance(ProxyManager)
877
+ await usingAsync(createInjector(), async (injector) => {
909
878
  const targetPort = getPort()
910
879
  const proxyPort = getPort()
911
880
 
@@ -922,7 +891,8 @@ describe('ProxyManager', () => {
922
891
  })
923
892
 
924
893
  try {
925
- await proxyManager.addProxy({
894
+ await useProxy({
895
+ injector,
926
896
  sourceBaseUrl: '/api',
927
897
  targetBaseUrl: `http://localhost:${targetPort}`,
928
898
  sourcePort: proxyPort,
@@ -941,8 +911,7 @@ describe('ProxyManager', () => {
941
911
  })
942
912
 
943
913
  it('Should handle undefined header values', async () => {
944
- await usingAsync(new Injector(), async (injector) => {
945
- const proxyManager = injector.getInstance(ProxyManager)
914
+ await usingAsync(createInjector(), async (injector) => {
946
915
  const targetPort = getPort()
947
916
  const proxyPort = getPort()
948
917
 
@@ -959,7 +928,8 @@ describe('ProxyManager', () => {
959
928
  })
960
929
 
961
930
  try {
962
- await proxyManager.addProxy({
931
+ await useProxy({
932
+ injector,
963
933
  sourceBaseUrl: '/api',
964
934
  targetBaseUrl: `http://localhost:${targetPort}`,
965
935
  sourcePort: proxyPort,
@@ -982,8 +952,7 @@ describe('ProxyManager', () => {
982
952
 
983
953
  describe('WebSocket proxy functionality', () => {
984
954
  it('Should proxy WebSocket connections when enabled', async () => {
985
- await usingAsync(new Injector(), async (injector) => {
986
- const proxyManager = injector.getInstance(ProxyManager)
955
+ await usingAsync(createInjector(), async (injector) => {
987
956
  const targetPort = getPort()
988
957
  const proxyPort = getPort()
989
958
 
@@ -996,7 +965,8 @@ describe('ProxyManager', () => {
996
965
 
997
966
  try {
998
967
  // Set up proxy with WebSocket support
999
- await proxyManager.addProxy({
968
+ await useProxy({
969
+ injector,
1000
970
  sourceBaseUrl: '/ws',
1001
971
  targetBaseUrl: `http://localhost:${targetPort}`,
1002
972
  sourcePort: proxyPort,
@@ -1030,8 +1000,7 @@ describe('ProxyManager', () => {
1030
1000
  })
1031
1001
 
1032
1002
  it('Should handle bidirectional WebSocket communication', async () => {
1033
- await usingAsync(new Injector(), async (injector) => {
1034
- const proxyManager = injector.getInstance(ProxyManager)
1003
+ await usingAsync(createInjector(), async (injector) => {
1035
1004
  const targetPort = getPort()
1036
1005
  const proxyPort = getPort()
1037
1006
 
@@ -1059,7 +1028,8 @@ describe('ProxyManager', () => {
1059
1028
  })
1060
1029
 
1061
1030
  try {
1062
- await proxyManager.addProxy({
1031
+ await useProxy({
1032
+ injector,
1063
1033
  sourceBaseUrl: '/ws',
1064
1034
  targetBaseUrl: `http://localhost:${targetPort}`,
1065
1035
  sourcePort: proxyPort,
@@ -1107,8 +1077,7 @@ describe('ProxyManager', () => {
1107
1077
  })
1108
1078
 
1109
1079
  it('Should not proxy WebSocket when disabled', async () => {
1110
- await usingAsync(new Injector(), async (injector) => {
1111
- const proxyManager = injector.getInstance(ProxyManager)
1080
+ await usingAsync(createInjector(), async (injector) => {
1112
1081
  const targetPort = getPort()
1113
1082
  const proxyPort = getPort()
1114
1083
 
@@ -1122,7 +1091,8 @@ describe('ProxyManager', () => {
1122
1091
 
1123
1092
  try {
1124
1093
  // Set up proxy WITHOUT WebSocket support
1125
- await proxyManager.addProxy({
1094
+ await useProxy({
1095
+ injector,
1126
1096
  sourceBaseUrl: '/ws',
1127
1097
  targetBaseUrl: `http://localhost:${targetPort}`,
1128
1098
  sourcePort: proxyPort,
@@ -1154,8 +1124,7 @@ describe('ProxyManager', () => {
1154
1124
  })
1155
1125
 
1156
1126
  it('Should preserve WebSocket subprotocols', async () => {
1157
- await usingAsync(new Injector(), async (injector) => {
1158
- const proxyManager = injector.getInstance(ProxyManager)
1127
+ await usingAsync(createInjector(), async (injector) => {
1159
1128
  const targetPort = getPort()
1160
1129
  const proxyPort = getPort()
1161
1130
 
@@ -1175,7 +1144,8 @@ describe('ProxyManager', () => {
1175
1144
  })
1176
1145
 
1177
1146
  try {
1178
- await proxyManager.addProxy({
1147
+ await useProxy({
1148
+ injector,
1179
1149
  sourceBaseUrl: '/ws',
1180
1150
  targetBaseUrl: `http://localhost:${targetPort}`,
1181
1151
  sourcePort: proxyPort,
@@ -1214,8 +1184,7 @@ describe('ProxyManager', () => {
1214
1184
  })
1215
1185
 
1216
1186
  it('Should handle WebSocket path rewriting', async () => {
1217
- await usingAsync(new Injector(), async (injector) => {
1218
- const proxyManager = injector.getInstance(ProxyManager)
1187
+ await usingAsync(createInjector(), async (injector) => {
1219
1188
  const targetPort = getPort()
1220
1189
  const proxyPort = getPort()
1221
1190
 
@@ -1235,7 +1204,8 @@ describe('ProxyManager', () => {
1235
1204
  })
1236
1205
 
1237
1206
  try {
1238
- await proxyManager.addProxy({
1207
+ await useProxy({
1208
+ injector,
1239
1209
  sourceBaseUrl: '/old/ws',
1240
1210
  targetBaseUrl: `http://localhost:${targetPort}`,
1241
1211
  sourcePort: proxyPort,
@@ -1271,8 +1241,7 @@ describe('ProxyManager', () => {
1271
1241
  })
1272
1242
 
1273
1243
  it('Should handle WebSocket connection closure from client', async () => {
1274
- await usingAsync(new Injector(), async (injector) => {
1275
- const proxyManager = injector.getInstance(ProxyManager)
1244
+ await usingAsync(createInjector(), async (injector) => {
1276
1245
  const targetPort = getPort()
1277
1246
  const proxyPort = getPort()
1278
1247
 
@@ -1293,7 +1262,8 @@ describe('ProxyManager', () => {
1293
1262
  })
1294
1263
 
1295
1264
  try {
1296
- await proxyManager.addProxy({
1265
+ await useProxy({
1266
+ injector,
1297
1267
  sourceBaseUrl: '/ws',
1298
1268
  targetBaseUrl: `http://localhost:${targetPort}`,
1299
1269
  sourcePort: proxyPort,
@@ -1328,8 +1298,7 @@ describe('ProxyManager', () => {
1328
1298
  })
1329
1299
 
1330
1300
  it('Should handle WebSocket connection closure from server', async () => {
1331
- await usingAsync(new Injector(), async (injector) => {
1332
- const proxyManager = injector.getInstance(ProxyManager)
1301
+ await usingAsync(createInjector(), async (injector) => {
1333
1302
  const targetPort = getPort()
1334
1303
  const proxyPort = getPort()
1335
1304
 
@@ -1348,7 +1317,8 @@ describe('ProxyManager', () => {
1348
1317
  })
1349
1318
 
1350
1319
  try {
1351
- await proxyManager.addProxy({
1320
+ await useProxy({
1321
+ injector,
1352
1322
  sourceBaseUrl: '/ws',
1353
1323
  targetBaseUrl: `http://localhost:${targetPort}`,
1354
1324
  sourcePort: proxyPort,
@@ -1388,18 +1358,18 @@ describe('ProxyManager', () => {
1388
1358
  })
1389
1359
 
1390
1360
  it('Should emit onWebSocketProxyFailed event on error', async () => {
1391
- await usingAsync(new Injector(), async (injector) => {
1392
- const proxyManager = injector.getInstance(ProxyManager)
1361
+ await usingAsync(createInjector(), async (injector) => {
1393
1362
  const proxyPort = getPort()
1394
1363
  const unavailablePort = getPort()
1395
1364
 
1396
1365
  let failedEvent: { from: string; to: string; error: unknown } | undefined
1397
1366
 
1398
- proxyManager.subscribe('onWebSocketProxyFailed', (event) => {
1367
+ injector.get(ServerTelemetryToken).subscribe('onWebSocketProxyFailed', (event) => {
1399
1368
  failedEvent = event
1400
1369
  })
1401
1370
 
1402
- await proxyManager.addProxy({
1371
+ await useProxy({
1372
+ injector,
1403
1373
  sourceBaseUrl: '/ws',
1404
1374
  targetBaseUrl: `http://localhost:${unavailablePort}`,
1405
1375
  sourcePort: proxyPort,
@@ -1427,8 +1397,7 @@ describe('ProxyManager', () => {
1427
1397
  })
1428
1398
 
1429
1399
  it('Should handle large WebSocket messages', async () => {
1430
- await usingAsync(new Injector(), async (injector) => {
1431
- const proxyManager = injector.getInstance(ProxyManager)
1400
+ await usingAsync(createInjector(), async (injector) => {
1432
1401
  const targetPort = getPort()
1433
1402
  const proxyPort = getPort()
1434
1403
 
@@ -1448,7 +1417,8 @@ describe('ProxyManager', () => {
1448
1417
  })
1449
1418
 
1450
1419
  try {
1451
- await proxyManager.addProxy({
1420
+ await useProxy({
1421
+ injector,
1452
1422
  sourceBaseUrl: '/ws',
1453
1423
  targetBaseUrl: `http://localhost:${targetPort}`,
1454
1424
  sourcePort: proxyPort,
@@ -1490,8 +1460,7 @@ describe('ProxyManager', () => {
1490
1460
  })
1491
1461
 
1492
1462
  it('Should handle binary WebSocket messages', async () => {
1493
- await usingAsync(new Injector(), async (injector) => {
1494
- const proxyManager = injector.getInstance(ProxyManager)
1463
+ await usingAsync(createInjector(), async (injector) => {
1495
1464
  const targetPort = getPort()
1496
1465
  const proxyPort = getPort()
1497
1466
 
@@ -1511,7 +1480,8 @@ describe('ProxyManager', () => {
1511
1480
  })
1512
1481
 
1513
1482
  try {
1514
- await proxyManager.addProxy({
1483
+ await useProxy({
1484
+ injector,
1515
1485
  sourceBaseUrl: '/ws',
1516
1486
  targetBaseUrl: `http://localhost:${targetPort}`,
1517
1487
  sourcePort: proxyPort,
@@ -1548,8 +1518,7 @@ describe('ProxyManager', () => {
1548
1518
  })
1549
1519
 
1550
1520
  it('Should apply header transformations to WebSocket upgrade', async () => {
1551
- await usingAsync(new Injector(), async (injector) => {
1552
- const proxyManager = injector.getInstance(ProxyManager)
1521
+ await usingAsync(createInjector(), async (injector) => {
1553
1522
  const targetPort = getPort()
1554
1523
  const proxyPort = getPort()
1555
1524
 
@@ -1569,7 +1538,8 @@ describe('ProxyManager', () => {
1569
1538
  })
1570
1539
 
1571
1540
  try {
1572
- await proxyManager.addProxy({
1541
+ await useProxy({
1542
+ injector,
1573
1543
  sourceBaseUrl: '/ws',
1574
1544
  targetBaseUrl: `http://localhost:${targetPort}`,
1575
1545
  sourcePort: proxyPort,
@@ -1609,8 +1579,7 @@ describe('ProxyManager', () => {
1609
1579
  })
1610
1580
 
1611
1581
  it('Should handle WebSocket upgrade timeout', async () => {
1612
- await usingAsync(new Injector(), async (injector) => {
1613
- const proxyManager = injector.getInstance(ProxyManager)
1582
+ await usingAsync(createInjector(), async (injector) => {
1614
1583
  const targetPort = getPort()
1615
1584
  const proxyPort = getPort()
1616
1585
 
@@ -1626,7 +1595,8 @@ describe('ProxyManager', () => {
1626
1595
  })
1627
1596
 
1628
1597
  try {
1629
- await proxyManager.addProxy({
1598
+ await useProxy({
1599
+ injector,
1630
1600
  sourceBaseUrl: '/ws',
1631
1601
  targetBaseUrl: `http://localhost:${targetPort}`,
1632
1602
  sourcePort: proxyPort,
@@ -1663,14 +1633,13 @@ describe('ProxyManager', () => {
1663
1633
  }, 10000)
1664
1634
 
1665
1635
  it('Should handle unusual path in WebSocket upgrade with PathHelper', async () => {
1666
- await usingAsync(new Injector(), async (injector) => {
1667
- const proxyManager = injector.getInstance(ProxyManager)
1636
+ await usingAsync(createInjector(), async (injector) => {
1668
1637
  const targetPort = getPort()
1669
1638
  const proxyPort = getPort()
1670
1639
 
1671
1640
  let failedEvent: { from: string; to: string; error: unknown } | undefined
1672
1641
 
1673
- proxyManager.subscribe('onWebSocketProxyFailed', (event) => {
1642
+ injector.get(ServerTelemetryToken).subscribe('onWebSocketProxyFailed', (event) => {
1674
1643
  failedEvent = event
1675
1644
  })
1676
1645
 
@@ -1688,7 +1657,8 @@ describe('ProxyManager', () => {
1688
1657
  })
1689
1658
 
1690
1659
  try {
1691
- await proxyManager.addProxy({
1660
+ await useProxy({
1661
+ injector,
1692
1662
  sourceBaseUrl: '/ws',
1693
1663
  targetBaseUrl: `http://localhost:${targetPort}`,
1694
1664
  sourcePort: proxyPort,
@@ -1724,8 +1694,7 @@ describe('ProxyManager', () => {
1724
1694
  })
1725
1695
 
1726
1696
  it('Should handle WebSocket header value types (number, array, undefined)', async () => {
1727
- await usingAsync(new Injector(), async (injector) => {
1728
- const proxyManager = injector.getInstance(ProxyManager)
1697
+ await usingAsync(createInjector(), async (injector) => {
1729
1698
  const targetPort = getPort()
1730
1699
  const proxyPort = getPort()
1731
1700
 
@@ -1738,7 +1707,8 @@ describe('ProxyManager', () => {
1738
1707
  })
1739
1708
 
1740
1709
  try {
1741
- await proxyManager.addProxy({
1710
+ await useProxy({
1711
+ injector,
1742
1712
  sourceBaseUrl: '/ws',
1743
1713
  targetBaseUrl: `http://localhost:${targetPort}`,
1744
1714
  sourcePort: proxyPort,
@@ -1777,8 +1747,7 @@ describe('ProxyManager', () => {
1777
1747
  })
1778
1748
 
1779
1749
  it('Should handle WebSocket connections with query parameters', async () => {
1780
- await usingAsync(new Injector(), async (injector) => {
1781
- const proxyManager = injector.getInstance(ProxyManager)
1750
+ await usingAsync(createInjector(), async (injector) => {
1782
1751
  const targetPort = getPort()
1783
1752
  const proxyPort = getPort()
1784
1753
 
@@ -1790,7 +1759,8 @@ describe('ProxyManager', () => {
1790
1759
  })
1791
1760
 
1792
1761
  try {
1793
- await proxyManager.addProxy({
1762
+ await useProxy({
1763
+ injector,
1794
1764
  sourceBaseUrl: '/ws',
1795
1765
  targetBaseUrl: `http://localhost:${targetPort}`,
1796
1766
  sourcePort: proxyPort,
@@ -1820,8 +1790,7 @@ describe('ProxyManager', () => {
1820
1790
  })
1821
1791
 
1822
1792
  it('Should handle WebSocket close with code and reason', async () => {
1823
- await usingAsync(new Injector(), async (injector) => {
1824
- const proxyManager = injector.getInstance(ProxyManager)
1793
+ await usingAsync(createInjector(), async (injector) => {
1825
1794
  const targetPort = getPort()
1826
1795
  const proxyPort = getPort()
1827
1796
 
@@ -1830,7 +1799,8 @@ describe('ProxyManager', () => {
1830
1799
  })
1831
1800
 
1832
1801
  try {
1833
- await proxyManager.addProxy({
1802
+ await useProxy({
1803
+ injector,
1834
1804
  sourceBaseUrl: '/ws',
1835
1805
  targetBaseUrl: `http://localhost:${targetPort}`,
1836
1806
  sourcePort: proxyPort,
@@ -1856,8 +1826,7 @@ describe('ProxyManager', () => {
1856
1826
 
1857
1827
  describe('HTTP Methods and Status Codes', () => {
1858
1828
  it('Should handle PUT requests with body', async () => {
1859
- await usingAsync(new Injector(), async (injector) => {
1860
- const proxyManager = injector.getInstance(ProxyManager)
1829
+ await usingAsync(createInjector(), async (injector) => {
1861
1830
  const targetPort = getPort()
1862
1831
  const proxyPort = getPort()
1863
1832
 
@@ -1872,7 +1841,8 @@ describe('ProxyManager', () => {
1872
1841
  })
1873
1842
 
1874
1843
  try {
1875
- await proxyManager.addProxy({
1844
+ await useProxy({
1845
+ injector,
1876
1846
  sourceBaseUrl: '/api',
1877
1847
  targetBaseUrl: `http://localhost:${targetPort}`,
1878
1848
  sourcePort: proxyPort,
@@ -1896,8 +1866,7 @@ describe('ProxyManager', () => {
1896
1866
  })
1897
1867
 
1898
1868
  it('Should handle PATCH requests with body', async () => {
1899
- await usingAsync(new Injector(), async (injector) => {
1900
- const proxyManager = injector.getInstance(ProxyManager)
1869
+ await usingAsync(createInjector(), async (injector) => {
1901
1870
  const targetPort = getPort()
1902
1871
  const proxyPort = getPort()
1903
1872
 
@@ -1912,7 +1881,8 @@ describe('ProxyManager', () => {
1912
1881
  })
1913
1882
 
1914
1883
  try {
1915
- await proxyManager.addProxy({
1884
+ await useProxy({
1885
+ injector,
1916
1886
  sourceBaseUrl: '/api',
1917
1887
  targetBaseUrl: `http://localhost:${targetPort}`,
1918
1888
  sourcePort: proxyPort,
@@ -1936,8 +1906,7 @@ describe('ProxyManager', () => {
1936
1906
  })
1937
1907
 
1938
1908
  it('Should handle DELETE requests', async () => {
1939
- await usingAsync(new Injector(), async (injector) => {
1940
- const proxyManager = injector.getInstance(ProxyManager)
1909
+ await usingAsync(createInjector(), async (injector) => {
1941
1910
  const targetPort = getPort()
1942
1911
  const proxyPort = getPort()
1943
1912
 
@@ -1947,7 +1916,8 @@ describe('ProxyManager', () => {
1947
1916
  })
1948
1917
 
1949
1918
  try {
1950
- await proxyManager.addProxy({
1919
+ await useProxy({
1920
+ injector,
1951
1921
  sourceBaseUrl: '/api',
1952
1922
  targetBaseUrl: `http://localhost:${targetPort}`,
1953
1923
  sourcePort: proxyPort,
@@ -1965,8 +1935,7 @@ describe('ProxyManager', () => {
1965
1935
  })
1966
1936
 
1967
1937
  it('Should handle OPTIONS requests (CORS preflight)', async () => {
1968
- await usingAsync(new Injector(), async (injector) => {
1969
- const proxyManager = injector.getInstance(ProxyManager)
1938
+ await usingAsync(createInjector(), async (injector) => {
1970
1939
  const targetPort = getPort()
1971
1940
  const proxyPort = getPort()
1972
1941
 
@@ -1980,7 +1949,8 @@ describe('ProxyManager', () => {
1980
1949
  })
1981
1950
 
1982
1951
  try {
1983
- await proxyManager.addProxy({
1952
+ await useProxy({
1953
+ injector,
1984
1954
  sourceBaseUrl: '/api',
1985
1955
  targetBaseUrl: `http://localhost:${targetPort}`,
1986
1956
  sourcePort: proxyPort,
@@ -2000,8 +1970,7 @@ describe('ProxyManager', () => {
2000
1970
  })
2001
1971
 
2002
1972
  it('Should handle HEAD requests', async () => {
2003
- await usingAsync(new Injector(), async (injector) => {
2004
- const proxyManager = injector.getInstance(ProxyManager)
1973
+ await usingAsync(createInjector(), async (injector) => {
2005
1974
  const targetPort = getPort()
2006
1975
  const proxyPort = getPort()
2007
1976
 
@@ -2014,7 +1983,8 @@ describe('ProxyManager', () => {
2014
1983
  })
2015
1984
 
2016
1985
  try {
2017
- await proxyManager.addProxy({
1986
+ await useProxy({
1987
+ injector,
2018
1988
  sourceBaseUrl: '/api',
2019
1989
  targetBaseUrl: `http://localhost:${targetPort}`,
2020
1990
  sourcePort: proxyPort,
@@ -2034,8 +2004,7 @@ describe('ProxyManager', () => {
2034
2004
  })
2035
2005
 
2036
2006
  it('Should handle 4xx client error responses', async () => {
2037
- await usingAsync(new Injector(), async (injector) => {
2038
- const proxyManager = injector.getInstance(ProxyManager)
2007
+ await usingAsync(createInjector(), async (injector) => {
2039
2008
  const targetPort = getPort()
2040
2009
  const proxyPort = getPort()
2041
2010
 
@@ -2045,7 +2014,8 @@ describe('ProxyManager', () => {
2045
2014
  })
2046
2015
 
2047
2016
  try {
2048
- await proxyManager.addProxy({
2017
+ await useProxy({
2018
+ injector,
2049
2019
  sourceBaseUrl: '/api',
2050
2020
  targetBaseUrl: `http://localhost:${targetPort}`,
2051
2021
  sourcePort: proxyPort,
@@ -2063,8 +2033,7 @@ describe('ProxyManager', () => {
2063
2033
  })
2064
2034
 
2065
2035
  it('Should handle 5xx server error responses', async () => {
2066
- await usingAsync(new Injector(), async (injector) => {
2067
- const proxyManager = injector.getInstance(ProxyManager)
2036
+ await usingAsync(createInjector(), async (injector) => {
2068
2037
  const targetPort = getPort()
2069
2038
  const proxyPort = getPort()
2070
2039
 
@@ -2074,7 +2043,8 @@ describe('ProxyManager', () => {
2074
2043
  })
2075
2044
 
2076
2045
  try {
2077
- await proxyManager.addProxy({
2046
+ await useProxy({
2047
+ injector,
2078
2048
  sourceBaseUrl: '/api',
2079
2049
  targetBaseUrl: `http://localhost:${targetPort}`,
2080
2050
  sourcePort: proxyPort,