mirror of
https://github.com/Tomato6966/investment-portfolio-simulator.git
synced 2025-04-12 08:48:42 +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
|
- name: Build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
env:
|
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
|
- name: Create 404.html
|
||||||
run: cp dist/index.html dist/404.html
|
run: cp dist/index.html dist/404.html
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,9 @@ interface YahooChartResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDev = import.meta.env.DEV;
|
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[]> => {
|
export const searchAssets = async (query: string): Promise<Asset[]> => {
|
||||||
try {
|
try {
|
||||||
|
@ -48,10 +50,7 @@ export const searchAssets = async (query: string): Promise<Asset[]> => {
|
||||||
type: 'equity,etf',
|
type: 'equity,etf',
|
||||||
});
|
});
|
||||||
|
|
||||||
const url = isDev
|
const url = `${API_BASE}/v1/finance/lookup?${params}`;
|
||||||
? `${API_BASE}/v1/finance/lookup?${params}`
|
|
||||||
: `${API_BASE}/v1/finance/lookup?${params}`;
|
|
||||||
|
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
if (!response.ok) throw new Error('Network response was not ok');
|
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',
|
interval: '1d',
|
||||||
});
|
});
|
||||||
|
|
||||||
const url = isDev
|
const url = `${API_BASE}/v8/finance/chart/${symbol}?${params}`;
|
||||||
? `/yahoo/v8/finance/chart/${symbol}?${params}`
|
|
||||||
: `${API_BASE}/v8/finance/chart/${symbol}?${params}`;
|
|
||||||
|
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
if (!response.ok) throw new Error('Network response was not ok');
|
if (!response.ok) throw new Error('Network response was not ok');
|
||||||
|
|
|
@ -12,8 +12,8 @@ export default defineConfig(({ mode }) => {
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
exclude: ['lucide-react'],
|
exclude: ['lucide-react'],
|
||||||
},
|
},
|
||||||
server: {
|
server: isDev ? {
|
||||||
proxy: isDev ? {
|
proxy: {
|
||||||
'/yahoo': {
|
'/yahoo': {
|
||||||
target: 'https://query1.finance.yahoo.com',
|
target: 'https://query1.finance.yahoo.com',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
|
@ -22,8 +22,8 @@ export default defineConfig(({ mode }) => {
|
||||||
'Origin': 'https://finance.yahoo.com'
|
'Origin': 'https://finance.yahoo.com'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} : undefined
|
}
|
||||||
},
|
} : undefined,
|
||||||
base: env.VITE_BASE_URL || '/',
|
base: env.VITE_BASE_URL || '/',
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue