Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
VCCI-News
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Văn Hoàng
VCCI-News
Commits
24f675cf
Commit
24f675cf
authored
Aug 13, 2026
by
Lê Bảo Hồng Đức
☄
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix route member,partner
parent
c152d34d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
54 deletions
+40
-54
route.ts
src/app/api/featured-members/route.ts
+20
-27
route.ts
src/app/api/partners/route.ts
+20
-27
No files found.
src/app/api/featured-members/route.ts
View file @
24f675cf
...
...
@@ -2,56 +2,49 @@ import { NextResponse } from "next/server";
import
{
MOCK_FEATURED_MEMBERS_RESPONSE
}
from
"@/app/api/mock-data"
;
const
BACKEND_HOST
=
process
.
env
.
NEXT_PUBLIC_BACKEND_HOST
||
"https://news.vccihcm.vn"
;
const
FEATURED_MEMBER_API_URL
=
`
${
BACKEND_HOST
.
replace
(
/
\/
+$/
,
""
)}
/api/v1.0/vcci/featured-members`
;
const
BACKEND_
FEATURED_MEMBER_API_URL
=
`
${
BACKEND_HOST
.
replace
(
/
\/
+$/
,
""
)}
/api/v1.0/vcci/featured-members`
;
//
Fallback: gọi trực tiếp VCCI HCM API
const
FALLBACK
_FEATURED_MEMBER_API_URL
=
//
Ưu tiên gọi trực tiếp VCCI HCM API (BE hiện chưa có endpoint này)
const
VCCI
_FEATURED_MEMBER_API_URL
=
"https://vccihcm.vn/api/v1.0/organizations"
+
"?filters=users.status_id+%3D%3D+36ca1cc5-7b6e-4f9f-b973-69c5207deb62"
+
"&pageSize=12&sortField=created_at&sortOrder=ASC"
;
export
async
function
GET
()
{
// 1) Ưu tiên VCCI HCM API
try
{
const
response
=
await
fetch
(
FEATURED_MEMBER_API_URL
,
{
const
response
=
await
fetch
(
VCCI_
FEATURED_MEMBER_API_URL
,
{
headers
:
{
Accept
:
"application/json"
},
next
:
{
revalidate
:
300
},
});
if
(
!
response
.
ok
)
{
console
.
warn
(
`[api/featured-members] upstream returned
${
response
.
status
}
, trying fallback`
,
);
// Thử fallback - gọi trực tiếp VCCI HCM API
return
tryFallback
();
}
if
(
response
.
ok
)
{
const
data
=
await
response
.
json
();
return
NextResponse
.
json
(
data
);
}
console
.
warn
(
`[api/featured-members] VCCI API returned
${
response
.
status
}
, trying backend`
);
}
catch
(
error
)
{
console
.
error
(
"[api/featured-members] upstream failed, trying fallback"
,
error
);
return
tryFallback
();
console
.
error
(
"[api/featured-members] VCCI API failed, trying backend"
,
error
);
}
}
async
function
tryFallback
()
{
// 2) Fallback: BE endpoint (nếu có)
try
{
const
fallbackResponse
=
await
fetch
(
FALLBACK
_FEATURED_MEMBER_API_URL
,
{
const
response
=
await
fetch
(
BACKEND
_FEATURED_MEMBER_API_URL
,
{
headers
:
{
Accept
:
"application/json"
},
next
:
{
revalidate
:
300
},
});
if
(
!
fallbackResponse
.
ok
)
{
console
.
warn
(
`[api/featured-members] fallback returned
${
fallbackResponse
.
status
}
, serving mock data`
,
);
return
NextResponse
.
json
(
MOCK_FEATURED_MEMBERS_RESPONSE
,
{
status
:
200
});
if
(
response
.
ok
)
{
const
data
=
await
response
.
json
();
return
NextResponse
.
json
(
data
);
}
const
data
=
await
fallbackResponse
.
json
();
console
.
log
(
"[api/featured-members] served from fallback"
);
return
NextResponse
.
json
(
data
);
console
.
warn
(
`[api/featured-members] backend returned
${
response
.
status
}
, serving mock data`
);
}
catch
(
error
)
{
console
.
error
(
"[api/featured-members] fallback failed, serving mock data"
,
error
);
return
NextResponse
.
json
(
MOCK_FEATURED_MEMBERS_RESPONSE
,
{
status
:
200
});
console
.
error
(
"[api/featured-members] backend failed, serving mock data"
,
error
);
}
// 3) Cuối cùng: mock data
return
NextResponse
.
json
(
MOCK_FEATURED_MEMBERS_RESPONSE
,
{
status
:
200
});
}
src/app/api/partners/route.ts
View file @
24f675cf
...
...
@@ -2,56 +2,49 @@ import { NextResponse } from "next/server";
import
{
MOCK_PARTNERS_RESPONSE
}
from
"@/app/api/mock-data"
;
const
BACKEND_HOST
=
process
.
env
.
NEXT_PUBLIC_BACKEND_HOST
||
"https://news.vccihcm.vn"
;
const
PARTNER_API_URL
=
`
${
BACKEND_HOST
.
replace
(
/
\/
+$/
,
""
)}
/api/v1.0/vcci/partners`
;
const
BACKEND_
PARTNER_API_URL
=
`
${
BACKEND_HOST
.
replace
(
/
\/
+$/
,
""
)}
/api/v1.0/vcci/partners`
;
//
Fallback: gọi trực tiếp VCCI HCM API
const
FALLBACK
_PARTNER_API_URL
=
//
Ưu tiên gọi trực tiếp VCCI HCM API (BE hiện chưa có endpoint này)
const
VCCI
_PARTNER_API_URL
=
"https://vccihcm.vn/api/v1.0/organizations"
+
"?filters=type%3D%3DSPONSOR&pageSize=12"
+
"&sortField=sort_order&sortOrder=ASC"
;
export
async
function
GET
()
{
// 1) Ưu tiên VCCI HCM API
try
{
const
response
=
await
fetch
(
PARTNER_API_URL
,
{
const
response
=
await
fetch
(
VCCI_
PARTNER_API_URL
,
{
headers
:
{
Accept
:
"application/json"
},
next
:
{
revalidate
:
300
},
});
if
(
!
response
.
ok
)
{
console
.
warn
(
`[api/partners] upstream returned
${
response
.
status
}
, trying fallback`
,
);
// Thử fallback - gọi trực tiếp VCCI HCM API
return
tryFallback
();
}
if
(
response
.
ok
)
{
const
data
=
await
response
.
json
();
return
NextResponse
.
json
(
data
);
}
console
.
warn
(
`[api/partners] VCCI API returned
${
response
.
status
}
, trying backend`
);
}
catch
(
error
)
{
console
.
error
(
"[api/partners] upstream failed, trying fallback"
,
error
);
return
tryFallback
();
console
.
error
(
"[api/partners] VCCI API failed, trying backend"
,
error
);
}
}
async
function
tryFallback
()
{
// 2) Fallback: BE endpoint (nếu có)
try
{
const
fallbackResponse
=
await
fetch
(
FALLBACK
_PARTNER_API_URL
,
{
const
response
=
await
fetch
(
BACKEND
_PARTNER_API_URL
,
{
headers
:
{
Accept
:
"application/json"
},
next
:
{
revalidate
:
300
},
});
if
(
!
fallbackResponse
.
ok
)
{
console
.
warn
(
`[api/partners] fallback returned
${
fallbackResponse
.
status
}
, serving mock data`
,
);
return
NextResponse
.
json
(
MOCK_PARTNERS_RESPONSE
,
{
status
:
200
});
if
(
response
.
ok
)
{
const
data
=
await
response
.
json
();
return
NextResponse
.
json
(
data
);
}
const
data
=
await
fallbackResponse
.
json
();
console
.
log
(
"[api/partners] served from fallback"
);
return
NextResponse
.
json
(
data
);
console
.
warn
(
`[api/partners] backend returned
${
response
.
status
}
, serving mock data`
);
}
catch
(
error
)
{
console
.
error
(
"[api/partners] fallback failed, serving mock data"
,
error
);
return
NextResponse
.
json
(
MOCK_PARTNERS_RESPONSE
,
{
status
:
200
});
console
.
error
(
"[api/partners] backend failed, serving mock data"
,
error
);
}
// 3) Cuối cùng: mock data
return
NextResponse
.
json
(
MOCK_PARTNERS_RESPONSE
,
{
status
:
200
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment