From 6d4d111cfa75b00a9afd7bc64e81e71e6d6b6c39 Mon Sep 17 00:00:00 2001 From: PaddiM8 Date: Wed, 3 Jul 2024 02:06:05 +0200 Subject: [PATCH] web: Always use an absolute url when connecting to hubs --- docker-compose.dev.yml | 5 +- docker-compose.yml | 5 +- web/Dockerfile | 2 +- web/package-lock.json | 132 ++++++++++++++++++++++------------------- web/src/lib/hubs.ts | 6 +- 5 files changed, 83 insertions(+), 67 deletions(-) diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 95bdad8..26d59da 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -26,7 +26,7 @@ condition: service_healthy environment: PLANERA_FRONTENDURL: https://localhost:2000 - PLANERA_EMAILCONFIRMATION: false + PLANERA_EMAILCONFIRMATION: "false" PLANERA_POSTGRES__HOST: "db:5432" PLANERA_POSTGRES__USER: planera PLANERA_POSTGRES__PASSWORD: planera @@ -45,6 +45,7 @@ image: planera-web environment: ORIGIN: https://localhost:2000 + VITE_PUBLIC_API_URL: https://localhost:2000/api build: context: . - dockerfile: web/Dockerfile \ No newline at end of file + dockerfile: web/Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml index 21fa589..f0764dd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,8 +28,8 @@ condition: service_healthy environment: PLANERA_FRONTENDURL: http://localhost:2000 - PLANERA_EMAILCONFIRMATION: false - PLANERA_DISABLEREGISTRATION: false + PLANERA_EMAILCONFIRMATION: "false" + PLANERA_DISABLEREGISTRATION: "false" PLANERA_POSTGRES__HOST: "db:5432" PLANERA_POSTGRES__USER: planera PLANERA_POSTGRES__PASSWORD: planera @@ -46,3 +46,4 @@ restart: always environment: ORIGIN: http://localhost:2000 + VITE_PUBLIC_API_URL: https://localhost:2000/api diff --git a/web/Dockerfile b/web/Dockerfile index 1737673..6c38c53 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20.5 +FROM node:20.12 WORKDIR /app COPY ["web/package.json", "web/package-lock.json", "web/"] WORKDIR /app/web diff --git a/web/package-lock.json b/web/package-lock.json index 907d944..5453a0d 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -48,6 +48,15 @@ "node": ">=12" } }, + "node_modules/@fastify/busboy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", + "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==", + "dev": true, + "engines": { + "node": ">=14" + } + }, "node_modules/@fontsource-variable/inter": { "version": "5.0.4", "license": "OFL-1.1" @@ -541,23 +550,25 @@ } }, "node_modules/@sveltejs/kit": { - "version": "1.22.1", + "version": "1.30.4", + "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.30.4.tgz", + "integrity": "sha512-JSQIQT6XvdchCRQEm7BABxPC56WP5RYVONAi+09S8tmzeP43fBsRlr95bFmsTQM2RHBldfgQk+jgdnsKI75daA==", "dev": true, "hasInstallScript": true, - "license": "MIT", "dependencies": { - "@sveltejs/vite-plugin-svelte": "^2.4.1", + "@sveltejs/vite-plugin-svelte": "^2.5.0", "@types/cookie": "^0.5.1", "cookie": "^0.5.0", "devalue": "^4.3.1", "esm-env": "^1.0.0", "kleur": "^4.1.5", "magic-string": "^0.30.0", - "mime": "^3.0.0", + "mrmime": "^1.0.1", "sade": "^1.8.1", "set-cookie-parser": "^2.6.0", "sirv": "^2.0.2", - "undici": "~5.22.0" + "tiny-glob": "^0.2.9", + "undici": "^5.28.3" }, "bin": { "svelte-kit": "svelte-kit.js" @@ -566,35 +577,37 @@ "node": "^16.14 || >=18" }, "peerDependencies": { - "svelte": "^3.54.0 || ^4.0.0-next.0", + "svelte": "^3.54.0 || ^4.0.0-next.0 || ^5.0.0-next.0", "vite": "^4.0.0" } }, "node_modules/@sveltejs/vite-plugin-svelte": { - "version": "2.4.1", + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/@sveltejs/vite-plugin-svelte/-/vite-plugin-svelte-2.5.3.tgz", + "integrity": "sha512-erhNtXxE5/6xGZz/M9eXsmI7Pxa6MS7jyTy06zN3Ck++ldrppOnOlJwHHTsMC7DHDQdgUp4NAc4cDNQ9eGdB/w==", "dev": true, - "license": "MIT", "dependencies": { - "@sveltejs/vite-plugin-svelte-inspector": "^1.0.2", + "@sveltejs/vite-plugin-svelte-inspector": "^1.0.4", "debug": "^4.3.4", "deepmerge": "^4.3.1", "kleur": "^4.1.5", - "magic-string": "^0.30.0", - "svelte-hmr": "^0.15.1", + "magic-string": "^0.30.3", + "svelte-hmr": "^0.15.3", "vitefu": "^0.2.4" }, "engines": { "node": "^14.18.0 || >= 16" }, "peerDependencies": { - "svelte": "^3.54.0 || ^4.0.0-next.0", + "svelte": "^3.54.0 || ^4.0.0 || ^5.0.0-next.0", "vite": "^4.0.0" } }, "node_modules/@sveltejs/vite-plugin-svelte-inspector": { - "version": "1.0.2", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@sveltejs/vite-plugin-svelte-inspector/-/vite-plugin-svelte-inspector-1.0.4.tgz", + "integrity": "sha512-zjiuZ3yydBtwpF3bj0kQNV0YXe+iKE545QGZVTaylW3eAzFr+pJ/cwK8lZEaRp4JtaJXhD5DyWAV4AxLh6DgaQ==", "dev": true, - "license": "MIT", "dependencies": { "debug": "^4.3.4" }, @@ -603,7 +616,7 @@ }, "peerDependencies": { "@sveltejs/vite-plugin-svelte": "^2.2.0", - "svelte": "^3.54.0 || ^4.0.0-next.0", + "svelte": "^3.54.0 || ^4.0.0", "vite": "^4.0.0" } }, @@ -835,16 +848,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/busboy": { - "version": "1.6.0", - "dev": true, - "dependencies": { - "streamsearch": "^1.1.0" - }, - "engines": { - "node": ">=10.16.0" - } - }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -952,9 +955,10 @@ "integrity": "sha512-FAaLDaplstoRsDR8XGYH51znUN0UY7nMc6Z9/fvE8EXGwvJE9hu7W2vHwx1+bd6gCYnln9nLbzxFTrcO9YQDZw==" }, "node_modules/debug": { - "version": "4.3.4", + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.5.tgz", + "integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==", "dev": true, - "license": "MIT", "dependencies": { "ms": "2.1.2" }, @@ -1382,6 +1386,18 @@ "node": ">= 6" } }, + "node_modules/globalyzer": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/globalyzer/-/globalyzer-0.1.0.tgz", + "integrity": "sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==", + "dev": true + }, + "node_modules/globrex": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/globrex/-/globrex-0.1.2.tgz", + "integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==", + "dev": true + }, "node_modules/graceful-fs": { "version": "4.2.11", "dev": true, @@ -1657,8 +1673,9 @@ }, "node_modules/kleur": { "version": "4.1.5", + "resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz", + "integrity": "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==", "dev": true, - "license": "MIT", "engines": { "node": ">=6" } @@ -1837,14 +1854,12 @@ "optional": true }, "node_modules/magic-string": { - "version": "0.30.0", + "version": "0.30.10", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.10.tgz", + "integrity": "sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==", "dev": true, - "license": "MIT", "dependencies": { - "@jridgewell/sourcemap-codec": "^1.4.13" - }, - "engines": { - "node": ">=12" + "@jridgewell/sourcemap-codec": "^1.4.15" } }, "node_modules/media-typer": { @@ -1887,17 +1902,6 @@ "node": ">=8.6" } }, - "node_modules/mime": { - "version": "3.0.0", - "dev": true, - "license": "MIT", - "bin": { - "mime": "cli.js" - }, - "engines": { - "node": ">=10.0.0" - } - }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -2571,13 +2575,6 @@ "node": ">= 0.8" } }, - "node_modules/streamsearch": { - "version": "1.1.0", - "dev": true, - "engines": { - "node": ">=10.0.0" - } - }, "node_modules/string_decoder": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", @@ -2650,14 +2647,15 @@ } }, "node_modules/svelte-hmr": { - "version": "0.15.2", + "version": "0.15.3", + "resolved": "https://registry.npmjs.org/svelte-hmr/-/svelte-hmr-0.15.3.tgz", + "integrity": "sha512-41snaPswvSf8TJUhlkoJBekRrABDXDMdpNpT2tfHIv4JuhgvHqLMhEPGtaQn0BmbNSTkuz2Ed20DF2eHw0SmBQ==", "dev": true, - "license": "ISC", "engines": { "node": "^12.20 || ^14.13.1 || >= 16" }, "peerDependencies": { - "svelte": "^3.19.0 || ^4.0.0-next.0" + "svelte": "^3.19.0 || ^4.0.0" } }, "node_modules/svelte-preprocess": { @@ -2732,6 +2730,16 @@ "node": ">=12" } }, + "node_modules/tiny-glob": { + "version": "0.2.9", + "resolved": "https://registry.npmjs.org/tiny-glob/-/tiny-glob-0.2.9.tgz", + "integrity": "sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg==", + "dev": true, + "dependencies": { + "globalyzer": "0.1.0", + "globrex": "^0.1.2" + } + }, "node_modules/to-regex-range": { "version": "5.0.1", "license": "MIT", @@ -2805,11 +2813,12 @@ } }, "node_modules/undici": { - "version": "5.22.1", + "version": "5.28.4", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz", + "integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==", "dev": true, - "license": "MIT", "dependencies": { - "busboy": "^1.6.0" + "@fastify/busboy": "^2.0.0" }, "engines": { "node": ">=14.0" @@ -2908,11 +2917,12 @@ } }, "node_modules/vitefu": { - "version": "0.2.4", + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/vitefu/-/vitefu-0.2.5.tgz", + "integrity": "sha512-SgHtMLoqaeeGnd2evZ849ZbACbnwQCIwRH57t18FxcXoZop0uQu0uzlIhJBlF/eWVzuce0sHeqPcDo+evVcg8Q==", "dev": true, - "license": "MIT", "peerDependencies": { - "vite": "^3.0.0 || ^4.0.0" + "vite": "^3.0.0 || ^4.0.0 || ^5.0.0" }, "peerDependenciesMeta": { "vite": { diff --git a/web/src/lib/hubs.ts b/web/src/lib/hubs.ts index 19c0313..96a2f3c 100644 --- a/web/src/lib/hubs.ts +++ b/web/src/lib/hubs.ts @@ -1,8 +1,12 @@ import {type HubConnection, HubConnectionBuilder} from "@microsoft/signalr"; async function buildHub(name: string): Promise { + // Make sure the url is absolute + const apiUrl = import.meta.env.VITE_PUBLIC_API_URL.match(/^https?:\/\//) + ? import.meta.env.VITE_PUBLIC_API_URL + : window.location.origin + import.meta.env.VITE_PUBLIC_API_URL return new HubConnectionBuilder() - .withUrl(`${import.meta.env.VITE_PUBLIC_API_URL}/hubs/${name}`) + .withUrl(`${apiUrl}/hubs/${name}`) .withAutomaticReconnect() .build(); }