Added envs for prod

This commit is contained in:
tomato6966 2024-12-21 23:30:18 +01:00
parent 8943000b84
commit 626e6944ac
5 changed files with 40 additions and 23 deletions

3
.env Normal file
View file

@ -0,0 +1,3 @@
VITE_YAHOO_API_URL=https://query1.finance.yahoo.com
VITE_YAHOO_ORIGIN=https://finance.yahoo.com

View file

@ -3,15 +3,14 @@ name: Deploy to GitHub Pages
on: on:
push: push:
branches: branches:
- main # oder master, je nachdem welchen Branch-Namen Sie verwenden - main
workflow_dispatch: # Ermöglicht manuelles Triggern workflow_dispatch:
permissions: permissions:
contents: read contents: read
pages: write pages: write
id-token: write id-token: write
# Erlaubt nur einen gleichzeitigen Deploy
concurrency: concurrency:
group: "pages" group: "pages"
cancel-in-progress: true cancel-in-progress: true
@ -39,6 +38,11 @@ jobs:
run: npm run build run: npm run build
env: env:
VITE_BASE_URL: '/${{ github.event.repository.name }}' 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 - name: Setup Pages
uses: actions/configure-pages@v4 uses: actions/configure-pages@v4

View file

@ -12,8 +12,8 @@ Why this Project?
- Portfolio Performance & Value - 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 - 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) ![Dark Mode Preview](./docs/preview-dark.png)
![Light Mode Preview](./preview-light.png) ![Light Mode Preview](./docs/preview-light.png)
## Features ## Features

View file

@ -37,6 +37,8 @@ interface YahooChartResult {
}; };
} }
const API_BASE = import.meta.env.VITE_YAHOO_API_URL || '/yahoo';
export const searchAssets = async (query: string): Promise<Asset[]> => { export const searchAssets = async (query: string): Promise<Asset[]> => {
try { try {
const params = new URLSearchParams({ const params = new URLSearchParams({
@ -45,7 +47,11 @@ export const searchAssets = async (query: string): Promise<Asset[]> => {
type: 'equity,etf', 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'); if (!response.ok) throw new Error('Network response was not ok');
const data = await response.json() as YahooSearchResponse; const data = await response.json() as YahooSearchResponse;

View file

@ -1,24 +1,28 @@
import { defineConfig } from "vite"; import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react"; import react from "@vitejs/plugin-react";
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig(({ mode }) => {
plugins: [react()], const env = loadEnv(mode, process.cwd(), '');
optimizeDeps: {
exclude: ['lucide-react'], return {
}, plugins: [react()],
server: { optimizeDeps: {
proxy: { exclude: ['lucide-react'],
'/yahoo': { },
target: 'https://query1.finance.yahoo.com', server: {
changeOrigin: true, proxy: {
rewrite: (path) => path.replace(/^\/yahoo/, ''), '/yahoo': {
headers: { target: env.VITE_YAHOO_API_URL || 'https://query1.finance.yahoo.com',
'Origin': 'https://finance.yahoo.com' changeOrigin: true,
rewrite: (path) => path.replace(/^\/yahoo/, ''),
headers: {
'Origin': env.VITE_YAHOO_ORIGIN || 'https://finance.yahoo.com'
}
} }
} }
} },
}, base: env.VITE_BASE_URL || '/',
base: process.env.VITE_BASE_URL || '/', };
}); });