@enfyra/sdk-nuxt 0.3.25 → 0.3.28

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.25",
7
+ "version": "0.3.28",
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): Promise<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,gBAY7D"}
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,4BA4B7D"}
@@ -1,13 +1,29 @@
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 || {};
17
+ const isWebSocket = event.node.req.headers["upgrade"]?.toLowerCase() === "websocket";
18
+ if (isWebSocket) {
19
+ proxy.web(event.node.req, event.node.res, {
20
+ target: targetUrl,
21
+ ws: true,
22
+ changeOrigin: true,
23
+ headers
24
+ });
25
+ return void 0;
26
+ }
11
27
  return proxyRequest(event, targetUrl, {
12
28
  headers
13
29
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enfyra/sdk-nuxt",
3
- "version": "0.3.25",
3
+ "version": "0.3.28",
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",
@@ -72,4 +74,4 @@
72
74
  "vite-plugin-dts": "^4.3.0",
73
75
  "vitest": "^3.2.4"
74
76
  }
75
- }
77
+ }
@@ -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;
@@ -12,6 +20,22 @@ export function proxyToAPI(event: H3Event, customPath?: string) {
12
20
 
13
21
  const headers = event.context.proxyHeaders || {};
14
22
 
23
+ // Detect WebSocket upgrade request
24
+ const isWebSocket = event.node.req.headers['upgrade']?.toLowerCase() === 'websocket';
25
+
26
+ if (isWebSocket) {
27
+ // For WebSocket, use http-proxy directly and return immediately
28
+ // The proxy will handle the upgrade asynchronously
29
+ proxy.web(event.node.req, event.node.res, {
30
+ target: targetUrl,
31
+ ws: true,
32
+ changeOrigin: true,
33
+ headers,
34
+ });
35
+ // Return undefined to signal we've handled the response asynchronously
36
+ return undefined;
37
+ }
38
+
15
39
  return proxyRequest(event, targetUrl, {
16
40
  headers,
17
41
  });