Skip to content

Commit

Permalink
Merge pull request #10 from vitelabs/test
Browse files Browse the repository at this point in the history
add news api
  • Loading branch information
KarlChristomer authored Sep 26, 2023
2 parents beb3407 + 85059e1 commit 65de319
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion content/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"tryit": "https://bridge-buidl.vite.net/"
},
"news": {
"api": "https://vite.org/api/discover_en.json",
"api": "/api/news",
"home": "https://medium.com/vitelabs",
"weeklyReport": "https://medium.com/vitelabs/tagged/project-updates",
"ann": "https://medium.com/vitelabs/announcements/home",
Expand Down
8 changes: 5 additions & 3 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ const news = reactive<any>([]);
onMounted(async () => {
try {
const { data }: {data: any} = await useFetch(links.news.api);
const resp = await fetch(links.news.api);
const data = await resp.json();
let n = 9;
if (isMobile) {
n = 5;
}
if (data.value) {
const found = data.value.tags?.find((x: any) => x.tag === 'news');
if (data) {
const found = data.tags?.find((x: any) => x.tag === 'news');
if (found) {
const list = found.list.slice(0, n).map((x: any) => {
const d = new Date(x.createTime * 1000);
Expand All @@ -36,6 +37,7 @@ onMounted(async () => {
}
}
} catch (e) {
console.log(e);
/* handle error */
}
})
Expand Down
8 changes: 8 additions & 0 deletions server/api/news.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default defineEventHandler(async (event) => {
setHeaders(event, {
'Content-Type': 'application/json; charset=utf-8'
});
const response = await fetch('https://static.vite.net//testnet-vite-1257137467/discover/discover_en.json');
const body = await response.text();
return body;
})

0 comments on commit 65de319

Please sign in to comment.