File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,8 +27,10 @@ function reducer(_: State, action: Action): State {
2727 return { status : "error" } ;
2828}
2929
30- const BACKEND_URL =
31- process . env . NEXT_PUBLIC_BACKEND_URL ?? "http://localhost:8080" ;
30+ // 默认走 Next.js rewrite 同源代理(见 next.config.mjs 的 /analytics/:path*),
31+ // 若需要跨域直连后端(比如本地 Next.js 未启动但要用 curl/别的客户端测接口),
32+ // 可设置 NEXT_PUBLIC_BACKEND_URL=http://localhost:8081 覆盖。
33+ const BACKEND_URL = process . env . NEXT_PUBLIC_BACKEND_URL ?? "" ;
3234
3335export function HotDocsTab ( { initialWindow } : { initialWindow : WindowParam } ) {
3436 const [ windowParam , setWindowParam ] = useReducer (
@@ -40,15 +42,17 @@ export function HotDocsTab({ initialWindow }: { initialWindow: WindowParam }) {
4042 useEffect ( ( ) => {
4143 dispatch ( { type : "fetch" } ) ;
4244 let cancelled = false ;
43- fetch (
44- `${ BACKEND_URL } /api/v1/analytics/top-docs?window=${ windowParam } &limit=20` ,
45- )
45+ fetch ( `${ BACKEND_URL } /analytics/top-docs?window=${ windowParam } &limit=20` )
4646 . then ( ( r ) => {
4747 if ( ! r . ok ) throw new Error ( ) ;
48- return r . json ( ) as Promise < HotDoc [ ] > ;
48+ return r . json ( ) as Promise < {
49+ success : boolean ;
50+ data : HotDoc [ ] ;
51+ } > ;
4952 } )
50- . then ( ( docs ) => {
51- if ( ! cancelled ) dispatch ( { type : "ok" , docs } ) ;
53+ . then ( ( body ) => {
54+ if ( ! body . success ) throw new Error ( ) ;
55+ if ( ! cancelled ) dispatch ( { type : "ok" , docs : body . data ?? [ ] } ) ;
5256 } )
5357 . catch ( ( ) => {
5458 if ( ! cancelled ) dispatch ( { type : "error" } ) ;
Original file line number Diff line number Diff line change @@ -36,6 +36,10 @@ const config = {
3636 source : "/auth/:path*" ,
3737 destination : `${ backendUrl } /auth/:path*` ,
3838 } ,
39+ {
40+ source : "/analytics/:path*" ,
41+ destination : `${ backendUrl } /analytics/:path*` ,
42+ } ,
3943 ] ;
4044 } ,
4145 images : {
You can’t perform that action at this time.
0 commit comments