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:
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

View file

@ -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

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[]> => {
try {
const params = new URLSearchParams({
@ -45,7 +47,11 @@ export const searchAssets = async (query: string): Promise<Asset[]> => {
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;

View file

@ -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 || '/',
};
});