diff --git a/.env b/.env new file mode 100644 index 0000000..94a5fd7 --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ + +VITE_YAHOO_API_URL=https://query1.finance.yahoo.com +VITE_YAHOO_ORIGIN=https://finance.yahoo.com diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e721bab..1199dac 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,15 +3,14 @@ name: Deploy to GitHub Pages on: push: branches: - - main # oder master, je nachdem welchen Branch-Namen Sie verwenden - workflow_dispatch: # Ermöglicht manuelles Triggern + - main + workflow_dispatch: permissions: contents: read pages: write id-token: write -# Erlaubt nur einen gleichzeitigen Deploy concurrency: group: "pages" cancel-in-progress: true @@ -39,6 +38,11 @@ jobs: run: npm run build env: VITE_BASE_URL: '/${{ github.event.repository.name }}' + VITE_YAHOO_API_URL: 'https://query1.finance.yahoo.com' + VITE_YAHOO_ORIGIN: 'https://finance.yahoo.com' + + - name: Create 404.html + run: cp dist/index.html dist/404.html - name: Setup Pages uses: actions/configure-pages@v4 diff --git a/README.md b/README.md index 669594a..7e2ecf0 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ Why this Project? - Portfolio Performance & Value - All assets (except the TTWOR and Portfolio-Value) are scaled by percentage of their price. Thus their referenced, scale is on the right. The referenced scale on the left is only for the portfolio-value -![Dark Mode Preview](./preview-dark.png) -![Light Mode Preview](./preview-light.png) +![Dark Mode Preview](./docs/preview-dark.png) +![Light Mode Preview](./docs/preview-light.png) ## Features diff --git a/src/services/yahooFinanceService.ts b/src/services/yahooFinanceService.ts index 4c51a0b..061a924 100644 --- a/src/services/yahooFinanceService.ts +++ b/src/services/yahooFinanceService.ts @@ -37,6 +37,8 @@ interface YahooChartResult { }; } +const API_BASE = import.meta.env.VITE_YAHOO_API_URL || '/yahoo'; + export const searchAssets = async (query: string): Promise => { try { const params = new URLSearchParams({ @@ -45,7 +47,11 @@ export const searchAssets = async (query: string): Promise => { type: 'equity,etf', }); - const response = await fetch(`/yahoo/v1/finance/lookup?${params}`); + const response = await fetch(`${API_BASE}/v1/finance/lookup?${params}`, { + headers: { + 'Origin': import.meta.env.VITE_YAHOO_ORIGIN || window.location.origin + } + }); if (!response.ok) throw new Error('Network response was not ok'); const data = await response.json() as YahooSearchResponse; diff --git a/vite.config.ts b/vite.config.ts index a396537..be1f3c8 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,24 +1,28 @@ -import { defineConfig } from "vite"; +import { defineConfig, loadEnv } from "vite"; import react from "@vitejs/plugin-react"; // https://vitejs.dev/config/ -export default defineConfig({ - plugins: [react()], - optimizeDeps: { - exclude: ['lucide-react'], - }, - server: { - proxy: { - '/yahoo': { - target: 'https://query1.finance.yahoo.com', - changeOrigin: true, - rewrite: (path) => path.replace(/^\/yahoo/, ''), - headers: { - 'Origin': 'https://finance.yahoo.com' +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd(), ''); + + return { + plugins: [react()], + optimizeDeps: { + exclude: ['lucide-react'], + }, + server: { + proxy: { + '/yahoo': { + target: env.VITE_YAHOO_API_URL || 'https://query1.finance.yahoo.com', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/yahoo/, ''), + headers: { + 'Origin': env.VITE_YAHOO_ORIGIN || 'https://finance.yahoo.com' + } } } - } - }, - base: process.env.VITE_BASE_URL || '/', + }, + base: env.VITE_BASE_URL || '/', + }; });