Skip to content

Commit 6bfc634

Browse files
authored
Merge pull request #1942 from walt-id/fix/portal2-local-testing
Fix/portal2 local testing
2 parents 48cbb3a + b013cfc commit 6bfc634

6 files changed

Lines changed: 1185 additions & 2 deletions

File tree

waltid-applications/waltid-web-portal2/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
NUXT_PUBLIC_ISSUER_BASE=http://localhost:7002
2+
NUXT_ISSUER_PROXY_TARGET=
23
NUXT_PUBLIC_VERIFIER_BASE=http://localhost:7003
4+
NUXT_VERIFIER_PROXY_TARGET=
35
NUXT_PUBLIC_WALLET_URL=http://localhost:7101
46
NUXT_PUBLIC_VERIFIER_KEY_JWK=
57
NUXT_PUBLIC_VERIFIER_X5C=

waltid-applications/waltid-web-portal2/nuxt.config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { defineNuxtConfig } from "nuxt/config";
22

3+
const issuerProxyTarget = process.env.NUXT_ISSUER_PROXY_TARGET?.replace(/\/+$/, "");
4+
const verifierProxyTarget = process.env.NUXT_VERIFIER_PROXY_TARGET?.replace(/\/+$/, "");
5+
36
export default defineNuxtConfig({
47
devtools: { enabled: true },
58
ssr: false,
@@ -17,9 +20,11 @@ export default defineNuxtConfig({
1720
runtimeConfig: {
1821
public: {
1922
issuerBase:
20-
process.env.NUXT_PUBLIC_ISSUER_BASE || "http://localhost:7005",
23+
process.env.NUXT_PUBLIC_ISSUER_BASE ||
24+
(issuerProxyTarget ? "/issuer-api" : "http://localhost:7005"),
2125
verifierBase:
22-
process.env.NUXT_PUBLIC_VERIFIER_BASE || "http://localhost:7004",
26+
process.env.NUXT_PUBLIC_VERIFIER_BASE ||
27+
(verifierProxyTarget ? "/verifier-api" : "http://localhost:7004"),
2328
walletUrl: process.env.NUXT_PUBLIC_WALLET_URL || "http://localhost:7101",
2429
verifierKeyJwk: process.env.NUXT_PUBLIC_VERIFIER_KEY_JWK || "",
2530
verifierX5c: process.env.NUXT_PUBLIC_VERIFIER_X5C || "",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineEventHandler } from "h3";
2+
import { proxyToTarget } from "../../utils/proxy";
3+
4+
export default defineEventHandler((event) =>
5+
proxyToTarget(event, /^\/issuer-api/, "NUXT_ISSUER_PROXY_TARGET"),
6+
);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineEventHandler } from "h3";
2+
import { proxyToTarget } from "../../utils/proxy";
3+
4+
export default defineEventHandler((event) =>
5+
proxyToTarget(event, /^\/verifier-api/, "NUXT_VERIFIER_PROXY_TARGET"),
6+
);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {
2+
createError,
3+
getRequestURL,
4+
type H3Event,
5+
proxyRequest,
6+
} from "h3";
7+
8+
export function proxyToTarget(event: H3Event, prefix: string | RegExp, envName: string) {
9+
const target = process.env[envName]?.replace(/\/+$/, "");
10+
11+
if (!target) {
12+
throw createError({
13+
statusCode: 502,
14+
statusMessage: `${envName} is not configured`,
15+
});
16+
}
17+
18+
const requestUrl = getRequestURL(event);
19+
const proxyPath = requestUrl.pathname.replace(prefix, "");
20+
21+
return proxyRequest(event, `${target}${proxyPath}${requestUrl.search}`, {
22+
headers: {
23+
"ngrok-skip-browser-warning": "true",
24+
},
25+
});
26+
}

0 commit comments

Comments
 (0)