stevekrouse-hntopstory.web.val.run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { fetch } from "https://esm.town/v/std/fetch";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
// Get the title of the top story on Hacker News
export async function hnTopStory() {
const topStories: Number[] = await fetch(
"https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty",
).then((res) => res.json());
const id = topStories[0];
const story: {
title: string;
url: string;
time: number;
type: string;
score: number;
by: string;
} = await fetchJSON(
`https://hacker-news.firebaseio.com/v0/item/${id}.json`,
);
return new Response(story.title);
}
// forked from @healeycodes.hnTopStories
// Forked from @jamiedubs.hnTopStories
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
3
roramigator avatar
roramigator(Edited )

There appears to be a problem, I guess the function wants to return a response:

return new Response(story.title, {status:200})```
stevekrouse avatar

Good catch, thanks! I fixed it

roramigator avatar

Awesome script 👍

August 13, 2024