mirror of
https://github.com/Tomato6966/investment-portfolio-simulator.git
synced 2025-04-07 11:50:36 +02:00
cors proxy
This commit is contained in:
parent
25588696d4
commit
4040d3a81a
4 changed files with 9 additions and 20 deletions
3
.env
3
.env
|
@ -1,3 +0,0 @@
|
|||
|
||||
VITE_YAHOO_API_URL=https://query1.finance.yahoo.com
|
||||
VITE_YAHOO_ORIGIN=https://finance.yahoo.com
|
4
.github/workflows/deploy.yml
vendored
4
.github/workflows/deploy.yml
vendored
|
@ -37,10 +37,6 @@ jobs:
|
|||
- name: Build
|
||||
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://tomato6966.github.io/'
|
||||
|
||||
- name: Create 404.html
|
||||
run: cp dist/index.html dist/404.html
|
||||
|
||||
|
|
|
@ -38,7 +38,9 @@ interface YahooChartResult {
|
|||
}
|
||||
|
||||
const isDev = import.meta.env.DEV;
|
||||
const API_BASE = isDev ? '/yahoo' : 'https://query1.finance.yahoo.com';
|
||||
const CORS_PROXY = 'https://corsproxy.io/?url=';
|
||||
const YAHOO_API = 'https://query1.finance.yahoo.com';
|
||||
const API_BASE = isDev ? '/yahoo' : `${CORS_PROXY}${encodeURIComponent(YAHOO_API)}`;
|
||||
|
||||
export const searchAssets = async (query: string): Promise<Asset[]> => {
|
||||
try {
|
||||
|
@ -48,10 +50,7 @@ export const searchAssets = async (query: string): Promise<Asset[]> => {
|
|||
type: 'equity,etf',
|
||||
});
|
||||
|
||||
const url = isDev
|
||||
? `${API_BASE}/v1/finance/lookup?${params}`
|
||||
: `${API_BASE}/v1/finance/lookup?${params}`;
|
||||
|
||||
const url = `${API_BASE}/v1/finance/lookup?${params}`;
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) throw new Error('Network response was not ok');
|
||||
|
||||
|
@ -97,10 +96,7 @@ export const getHistoricalData = async (symbol: string, startDate: string, endDa
|
|||
interval: '1d',
|
||||
});
|
||||
|
||||
const url = isDev
|
||||
? `/yahoo/v8/finance/chart/${symbol}?${params}`
|
||||
: `${API_BASE}/v8/finance/chart/${symbol}?${params}`;
|
||||
|
||||
const url = `${API_BASE}/v8/finance/chart/${symbol}?${params}`;
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) throw new Error('Network response was not ok');
|
||||
|
|
@ -12,8 +12,8 @@ export default defineConfig(({ mode }) => {
|
|||
optimizeDeps: {
|
||||
exclude: ['lucide-react'],
|
||||
},
|
||||
server: {
|
||||
proxy: isDev ? {
|
||||
server: isDev ? {
|
||||
proxy: {
|
||||
'/yahoo': {
|
||||
target: 'https://query1.finance.yahoo.com',
|
||||
changeOrigin: true,
|
||||
|
@ -22,8 +22,8 @@ export default defineConfig(({ mode }) => {
|
|||
'Origin': 'https://finance.yahoo.com'
|
||||
}
|
||||
}
|
||||
} : undefined
|
||||
},
|
||||
}
|
||||
} : undefined,
|
||||
base: env.VITE_BASE_URL || '/',
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue