File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import axios from 'axios'
22
3- // 根据环境自动选择 API 基础 URL
4- const getBaseURL = ( ) => {
5- // 优先使用环境变量
6- if ( import . meta. env . VITE_API_BASE_URL ) {
7- return import . meta. env . VITE_API_BASE_URL
8- }
9- // 默认使用本地后端(开发测试)
10- return 'http://localhost:8000'
11- }
3+ // API 基础 URL - 生产环境使用完整 URL
4+ const API_BASE_URL = 'http://localhost:8000'
125
136const api = axios . create ( {
14- baseURL : getBaseURL ( ) ,
7+ baseURL : API_BASE_URL ,
158 timeout : 30000 ,
169} )
1710
Original file line number Diff line number Diff line change @@ -81,9 +81,11 @@ const sources = [
8181const activeSource = ref (' netease' )
8282const chartData = ref ([])
8383
84+ const API_BASE_URL = ' http://localhost:8000'
85+
8486const fetchChart = async () => {
8587 try {
86- const response = await fetch (` /api/v1/chart/${activeSource .value }/new_songs?limit=20 ` )
88+ const response = await fetch (` ${ API_BASE_URL } /api/v1/chart/${activeSource .value }/new_songs?limit=20` )
8789 const data = await response .json ()
8890 chartData .value = data .entries || []
8991 } catch (error ) {
@@ -97,7 +99,7 @@ const playSong = (song: any) => {
9799
98100const subscribeSong = async (song : any ) => {
99101 try {
100- await fetch (' /api/v1/subscribes' , {
102+ await fetch (` ${ API_BASE_URL } /api/v1/subscribes` , {
101103 method: ' POST' ,
102104 headers: { ' Content-Type' : ' application/json' },
103105 body: JSON .stringify ({
Original file line number Diff line number Diff line change @@ -10,4 +10,12 @@ export default defineConfig({
1010 '@' : fileURLToPath ( new URL ( './src' , import . meta. url ) ) ,
1111 } ,
1212 } ,
13+ server : {
14+ proxy : {
15+ '/api' : {
16+ target : 'http://localhost:8000' ,
17+ changeOrigin : true ,
18+ } ,
19+ } ,
20+ } ,
1321} )
You can’t perform that action at this time.
0 commit comments