@enfyra/sdk-nuxt 0.3.26 → 0.3.29

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/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "0.3.26",
7
+ "version": "0.3.29",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
@@ -1,3 +1,3 @@
1
1
  import { H3Event } from "h3";
2
- export declare function proxyToAPI(event: H3Event, customPath?: string): any;
2
+ export declare function proxyToAPI(event: H3Event, customPath?: string): Promise<any> | undefined;
3
3
  //# sourceMappingURL=proxy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../../src/runtime/utils/server/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAgB,MAAM,IAAI,CAAC;AAK3C,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,OAyB7D"}
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../../src/runtime/utils/server/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAgB,MAAM,IAAI,CAAC;AAa3C,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,4BAmC7D"}
@@ -1,22 +1,31 @@
1
1
  import { proxyRequest } from "h3";
2
+ import { createProxy } from "http-proxy";
2
3
  import { useRuntimeConfig } from "#imports";
3
4
  import { ENFYRA_API_PREFIX } from "../../constants/config.js";
4
5
  import { normalizeUrl } from "../url.js";
6
+ const proxy = createProxy({
7
+ target: process.env.API_URL || "http://localhost:1105",
8
+ ws: true,
9
+ changeOrigin: true
10
+ });
5
11
  export function proxyToAPI(event, customPath) {
6
12
  const config = useRuntimeConfig();
7
13
  const apiPrefix = config.public?.enfyraSDK?.apiPrefix || ENFYRA_API_PREFIX;
8
14
  const rawPath = customPath || event.path.replace(new RegExp(`^${apiPrefix}`), "");
9
15
  const targetUrl = normalizeUrl(config.public?.enfyraSDK?.apiUrl, rawPath);
10
16
  const headers = event.context.proxyHeaders || {};
11
- const isWebSocket = event.headers.get("upgrade")?.toLowerCase() === "websocket";
17
+ const isWebSocket = event.node.req.headers["upgrade"]?.toLowerCase() === "websocket";
12
18
  if (isWebSocket) {
13
- return proxyRequest(event, targetUrl, {
14
- headers,
15
- fetchOptions: {
16
- // @ts-ignore - duplex is required for WebSocket in Node fetch
17
- duplex: "half"
18
- }
19
+ const originalUrl = event.node.req.url || "";
20
+ event.node.req.url = rawPath;
21
+ proxy.web(event.node.req, event.node.res, {
22
+ target: config.public?.enfyraSDK?.apiUrl || process.env.API_URL || "http://localhost:1105",
23
+ ws: true,
24
+ changeOrigin: true,
25
+ headers
19
26
  });
27
+ event.node.req.url = originalUrl;
28
+ return void 0;
20
29
  }
21
30
  return proxyRequest(event, targetUrl, {
22
31
  headers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enfyra/sdk-nuxt",
3
- "version": "0.3.26",
3
+ "version": "0.3.29",
4
4
  "type": "module",
5
5
  "description": "Nuxt SDK for Enfyra CMS",
6
6
  "repository": {
@@ -60,10 +60,12 @@
60
60
  "dependencies": {
61
61
  "defu": "^6.1.4",
62
62
  "h3": "^1.15.4",
63
+ "http-proxy": "^1.18.1",
63
64
  "ofetch": "^1.3.3"
64
65
  },
65
66
  "devDependencies": {
66
67
  "@nuxt/module-builder": "^0.8.4",
68
+ "@types/http-proxy": "^1.17.17",
67
69
  "@types/node": "^24.10.1",
68
70
  "@vitest/ui": "^3.2.4",
69
71
  "nuxt": "^3.18.1",
@@ -1,8 +1,16 @@
1
1
  import { H3Event, proxyRequest } from "h3";
2
+ import { createProxy } from "http-proxy";
2
3
  import { useRuntimeConfig } from "#imports";
3
4
  import { ENFYRA_API_PREFIX } from "../../constants/config";
4
5
  import { normalizeUrl } from "../url";
5
6
 
7
+ // Create proxy instance (reuse for performance)
8
+ const proxy = createProxy({
9
+ target: process.env.API_URL || 'http://localhost:1105',
10
+ ws: true,
11
+ changeOrigin: true,
12
+ });
13
+
6
14
  export function proxyToAPI(event: H3Event, customPath?: string) {
7
15
  const config = useRuntimeConfig();
8
16
  const apiPrefix = config.public?.enfyraSDK?.apiPrefix || ENFYRA_API_PREFIX;
@@ -13,16 +21,26 @@ export function proxyToAPI(event: H3Event, customPath?: string) {
13
21
  const headers = event.context.proxyHeaders || {};
14
22
 
15
23
  // Detect WebSocket upgrade request
16
- const isWebSocket = event.headers.get('upgrade')?.toLowerCase() === 'websocket';
24
+ const isWebSocket = event.node.req.headers['upgrade']?.toLowerCase() === 'websocket';
17
25
 
18
26
  if (isWebSocket) {
19
- return proxyRequest(event, targetUrl, {
27
+ // Modify req.url to remove the apiPrefix before proxying
28
+ // The incoming request is /api/chat/test-room but backend expects /chat/test-room
29
+ const originalUrl = event.node.req.url || '';
30
+ event.node.req.url = rawPath;
31
+
32
+ // For WebSocket, use http-proxy directly
33
+ proxy.web(event.node.req, event.node.res, {
34
+ target: config.public?.enfyraSDK?.apiUrl || process.env.API_URL || 'http://localhost:1105',
35
+ ws: true,
36
+ changeOrigin: true,
20
37
  headers,
21
- fetchOptions: {
22
- // @ts-ignore - duplex is required for WebSocket in Node fetch
23
- duplex: 'half',
24
- },
25
- }) as any;
38
+ });
39
+
40
+ // Restore original url
41
+ event.node.req.url = originalUrl;
42
+ // Return undefined to signal we've handled the response asynchronously
43
+ return undefined;
26
44
  }
27
45
 
28
46
  return proxyRequest(event, targetUrl, {