@enfyra/sdk-nuxt 0.3.26 → 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
|
@@ -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;
|
|
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,22 +1,28 @@
|
|
|
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
|
|
17
|
+
const isWebSocket = event.node.req.headers["upgrade"]?.toLowerCase() === "websocket";
|
|
12
18
|
if (isWebSocket) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
+
proxy.web(event.node.req, event.node.res, {
|
|
20
|
+
target: targetUrl,
|
|
21
|
+
ws: true,
|
|
22
|
+
changeOrigin: true,
|
|
23
|
+
headers
|
|
19
24
|
});
|
|
25
|
+
return void 0;
|
|
20
26
|
}
|
|
21
27
|
return proxyRequest(event, targetUrl, {
|
|
22
28
|
headers
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enfyra/sdk-nuxt",
|
|
3
|
-
"version": "0.3.
|
|
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",
|
|
@@ -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,19 @@ 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
|
|
24
|
+
const isWebSocket = event.node.req.headers['upgrade']?.toLowerCase() === 'websocket';
|
|
17
25
|
|
|
18
26
|
if (isWebSocket) {
|
|
19
|
-
|
|
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,
|
|
20
33
|
headers,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
}) as any;
|
|
34
|
+
});
|
|
35
|
+
// Return undefined to signal we've handled the response asynchronously
|
|
36
|
+
return undefined;
|
|
26
37
|
}
|
|
27
38
|
|
|
28
39
|
return proxyRequest(event, targetUrl, {
|