diff --git a/angular.json b/angular.json index e7c126d..0171cc3 100644 --- a/angular.json +++ b/angular.json @@ -68,7 +68,8 @@ "buildTarget": "qr_vitanova:build:production" }, "development": { - "buildTarget": "qr_vitanova:build:development" + "buildTarget": "qr_vitanova:build:development", + "proxyConfig": "proxy.conf.json" } }, "defaultConfiguration": "development" diff --git a/proxy.conf.json b/proxy.conf.json new file mode 100644 index 0000000..83d7baa --- /dev/null +++ b/proxy.conf.json @@ -0,0 +1,23 @@ +{ + "/proxy/legacy-qr": { + "target": "https://qr.vitanova.network:567", + "secure": false, + "changeOrigin": true, + "pathRewrite": { "^/proxy/legacy-qr": "" }, + "logLevel": "debug" + }, + "/proxy/fastcheck": { + "target": "https://api.fastcheck.store", + "secure": true, + "changeOrigin": true, + "pathRewrite": { "^/proxy/fastcheck": "" }, + "logLevel": "debug" + }, + "/proxy/qr-vitanova": { + "target": "https://qr.vitanova.network", + "secure": true, + "changeOrigin": true, + "pathRewrite": { "^/proxy/qr-vitanova": "" }, + "logLevel": "debug" + } +} diff --git a/src/app/api.ts b/src/app/api.ts index 5e75fbb..a64c274 100644 --- a/src/app/api.ts +++ b/src/app/api.ts @@ -1,11 +1,21 @@ -/** +import { isDevMode } from '@angular/core'; + +/** * Endpoint constants for the Fastcheck backend (see public/api.txt). * Centralised so they can be swapped in one place. + * In dev mode (ng serve) requests go through the Angular proxy (proxy.conf.json) + * to avoid CORS issues. In production the real URLs are used. */ -export const FASTCHECK_API = 'https://api.fastcheck.store'; +export const FASTCHECK_API = isDevMode() + ? '/proxy/fastcheck' + : 'https://api.fastcheck.store'; // Legacy QR endpoint kept for the SBP amount → payload redirect flow. -export const QR_API = 'https://qr.vitanova.network:567/qr'; +export const QR_API = isDevMode() + ? '/proxy/legacy-qr/qr' + : 'https://qr.vitanova.network:567/qr'; // New QR Vitanova API (dynamic QR, settings, polling). -export const QR_VITANOVA_API = 'https://qr.vitanova.network/api'; +export const QR_VITANOVA_API = isDevMode() + ? '/proxy/qr-vitanova/api' + : 'https://qr.vitanova.network/api'; diff --git a/src/app/pages/legacy-pay-page/legacy-pay-page.ts b/src/app/pages/legacy-pay-page/legacy-pay-page.ts index 0f2cc2a..5a1fbd4 100644 --- a/src/app/pages/legacy-pay-page/legacy-pay-page.ts +++ b/src/app/pages/legacy-pay-page/legacy-pay-page.ts @@ -1,4 +1,4 @@ -import { Component, computed, inject, signal } from '@angular/core'; +import { Component, computed, inject, isDevMode, signal } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { ActivatedRoute } from '@angular/router'; import { HttpClient } from '@angular/common/http'; @@ -30,7 +30,9 @@ export class LegacyPayPage { private t(key: string): string { return this.i18n.translate(key); } - private readonly LEGACY_API = 'https://qr.vitanova.network:567/qr'; + private readonly LEGACY_API = isDevMode() + ? '/proxy/legacy-qr/qr' + : 'https://qr.vitanova.network:567/qr'; amount = signal(null); note = signal(''); @@ -40,8 +42,9 @@ export class LegacyPayPage { paymentId = signal(''); - readonly isMobile: boolean = typeof navigator !== 'undefined' - && /android|iphone|ipad|ipod|mobile/i.test(navigator.userAgent); + readonly isMobile: boolean = typeof window !== 'undefined' + && (navigator.maxTouchPoints > 0 || 'ontouchstart' in window + || /android|iphone|ipad|ipod|mobile/i.test(navigator.userAgent)); canPay = computed(() => { const a = this.amount();