100}
101102return fetch(requestParams.url, preload).catch((err) => new Response(err.stack, { status: 500 }));
103});
104112// app.post("/v1/chat/completions", handleChatCompletionWrap);
113114export default app.fetch;
2// const baseUrl = "https://api.neynar.com/v2/farcaster/";
34export async function fetchNeynarGet(path: string) {
5const res = await fetch(baseUrl + encodeURIComponent(path), {
6method: 'GET',
7headers: {
15}
1617export async function fetchNeynarGetPages(path: string, pages: number, dataKey: string) {
18let data: any = []
19let cursor = ''
20let pagesLeft = pages
21while (true) {
22const res = await fetchNeynarGet(`${path}&cursor=${cursor}`)
23data = [...data, ...res[dataKey]]
24cursor = res?.next?.cursor
35//////////
3637export function fetchUser(username: string) {
38if (username.startsWith('fid:')) {
39return fetchUsersById(username.replace('fid:', '')).then((users) => users[0])
40}
41return fetchNeynarGet(`user/by_username?username=${username}`).then((r) => r.user)
42}
43export function fetchUsersById(fids: string) {
44return fetchNeynarGet(`user/bulk?fids=${fids}`).then((r) => r.users)
45}
4647export function fetchUserFeed(fid: string) {
48return fetchNeynarGet(
49`feed?feed_type=filter&filter_type=fids&fids=${fid}&with_recasts=false&with_replies=false&limit=100&cursor=`
50).then((r) => r.casts)
51}
5253export function fetchChannel(channelId: string) {
54return fetchNeynarGet(`channel?id=${channelId}`).then((r) => r.channel)
55}
5657export function fetchChannelFeed(channelId: string) {
58return fetchNeynarGet(`feed/channels?channel_ids=${channelId}&with_recasts=false&limit=100`).then((r) => r.casts)
59}
6061export function fetchChannelsFeed(channelIds: string[]) {
62return fetchNeynarGet(`feed/channels?channel_ids=${channelIds.join(',')}&with_recasts=false&limit=100`).then(
63(r) => r.casts
64)
65}
6667export function fetchCast(hash: string) {
68return fetchNeynarGet(`cast?type=hash&identifier=${hash}`).then((r) => r.cast)
69}
7071export function fetchCastReplies(hash: string) {
72return fetchNeynarGet(
73`cast/conversation?identifier=${hash}&type=hash&reply_depth=2&include_chronological_parent_casts=false&sort_type=algorithmic&fold=above&limit=20`
74).then((r) => r?.conversation?.cast?.direct_replies)
68//////////
6970export async function fetchProxyJSON(url: string) {
71const baseUrl = 'https://sonar.val.run/proxy?path='
72const res = await fetch(baseUrl + encodeURIComponent(url), {
73method: 'GET',
74headers: { 'Content-Type': 'application/json' },
78}
7980export async function fetchStarterPack(id: string | undefined) {
81if (!id) return null
82return await fetchProxyJSON(`https://client.farcaster.xyz/v2/starter-pack?id=${id}`).then(
83(r) => r?.result?.starterPack
84)
85}
8687export function fetchStarterPackMemberIds(id: string) {
88return fetch(`https://api.warpcast.com/fc/starter-pack-members?id=${id}`)
89.then((res) => res.json())
90.then((data) => data?.result?.members)
HTTP_exampleshonoExample1 match
4app.get("/", (c) => c.text("Hello from Hono!"));
5app.get("/yeah", (c) => c.text("Routing!"));
6export default app.fetch;
HTTP_examplesfetsExample1 match
21});
2223export default router.fetch;
215};
216
217const fetchMessages = async (retries = 3, delay = 1000) => {
218try {
219const response = await fetch('/messages');
220if (!response.ok) {
221const errorData = await response.json().catch(() => ({}));
227console.error(error);
228if (retries > 0) {
229setTimeout(() => fetchMessages(retries - 1, delay * 2), delay);
230} else {
231showStatus('Could not load community messages. ' + error.message, 'error');
246247try {
248const response = await fetch('/submit', {
249method: 'POST',
250headers: { 'Content-Type': 'application/json' },
260showStatus('Vibe approved! Your message is live.', 'success');
261form.reset();
262fetchMessages();
263264} catch (error) {
272273// Initial load
274fetchMessages();
275})();
276</script>
289});
290291// Route to fetch all approved messages
292app.get("/messages", async (c) => {
293try {
295return c.json(messages);
296} catch (error) {
297console.error("Failed to fetch messages from blob:", error);
298return c.json({ error: "Error fetching messages." }, 500);
299}
300});
361});
362363export default app.fetch;
reactHonoStarterindex.ts2 matches
21});
2223// HTTP vals expect an exported "fetch handler"
24// This is how you "run the server" in Val Town with Hono
25export default app.fetch;
reddit-checkerunified-reddit-monitor.ts26 matches
133const auth = btoa(`${REDDIT_CLIENT_ID}:${REDDIT_CLIENT_SECRET}`);
134135const response = await fetch("https://www.reddit.com/api/v1/access_token", {
136method: "POST",
137headers: {
163164/**
165* Fetches recent posts from a subreddit using Reddit API
166*/
167async function fetchSubredditPostsAPI(subreddit: string, limit: number = 25): Promise<RedditPost[]> {
168try {
169const accessToken = await getRedditAccessToken();
170const url = `https://oauth.reddit.com/r/${subreddit}/new?limit=${limit}`;
171172const response = await fetch(url, {
173headers: {
174"Authorization": `Bearer ${accessToken}`,
184return data.data.children.map(child => child.data);
185} catch (error) {
186console.error(`Error fetching posts from r/${subreddit} via API:`, error);
187throw error;
188}
190191/**
192* Fallback: Fetches recent posts using Reddit's JSON endpoint
193*/
194async function fetchSubredditPostsJSON(subreddit: string, limit: number = 25): Promise<RedditPost[]> {
195try {
196const url = `https://www.reddit.com/r/${subreddit}/new.json?limit=${limit}`;
197198const response = await fetch(url, {
199headers: {
200"User-Agent": "Mozilla/5.0 (compatible; UnifiedRedditMonitor/1.0; +https://val.town)",
212return data.data.children.map(child => child.data);
213} catch (error) {
214console.error(`Error fetching posts from r/${subreddit} via JSON:`, error);
215throw error;
216}
295296/**
297* Fallback: Fetches RSS feed from a subreddit and converts to RedditPost format
298*/
299async function fetchSubredditPostsRSS(subreddit: string): Promise<RedditPost[]> {
300try {
301const url = `https://www.reddit.com/r/${subreddit}/new.rss`;
302303const response = await fetch(url, {
304headers: {
305"User-Agent": "Mozilla/5.0 (compatible; UnifiedRedditMonitor/1.0; +https://val.town)",
330}));
331} catch (error) {
332console.error(`Error fetching RSS from r/${subreddit}:`, error);
333throw error;
334}
336337/**
338* Fetches posts from a subreddit with fallback methods
339*/
340async function fetchSubredditPosts(subreddit: string, limit: number = 25): Promise<RedditPost[]> {
341// Try API first
342try {
343console.log(` š” Trying Reddit API for r/${subreddit}...`);
344return await fetchSubredditPostsAPI(subreddit, limit);
345} catch (apiError) {
346console.log(` ā ļø API failed for r/${subreddit}, trying JSON endpoint...`);
348// Try JSON endpoint
349try {
350return await fetchSubredditPostsJSON(subreddit, limit);
351} catch (jsonError) {
352console.log(` ā ļø JSON failed for r/${subreddit}, trying RSS...`);
354// Try RSS as last resort
355try {
356return await fetchSubredditPostsRSS(subreddit);
357} catch (rssError) {
358console.error(` ā All methods failed for r/${subreddit}`);
359throw new Error(
360`All fetch methods failed for r/${subreddit}: API(${apiError.message}), JSON(${jsonError.message}), RSS(${rssError.message})`,
361);
362}
438};
439440const response = await fetch(SLACK_WEBHOOK_URL, {
441method: "POST",
442headers: {
515516try {
517const response = await fetch(`${SUPABASE_URL}/rest/v1/relevant_reddit_posts`, {
518method: "POST",
519headers: {
564if (CONFIG.useSlack) {
565try {
566await fetch(SLACK_WEBHOOK_URL, {
567method: "POST",
568headers: {
689690try {
691// Fetch recent posts from this subreddit (with fallback methods)
692const posts = await fetchSubredditPosts(subreddit, CONFIG.postLimit);
693console.log(` ā Fetched ${posts.length} posts from r/${subreddit}`);
694totalPosts += posts.length;
695724725console.log(`\nš Final Summary:`);
726console.log(`š„ Total posts fetched: ${totalPosts}`);
727console.log(`š Total new posts: ${totalNewPosts}`);
728console.log(`ā Total matches found: ${allMatchingPosts.length}`);
3export async function cronUrl(url: string) {
4try {
5const res = await fetch(url);
6console.log(`${url} ${res.status} `);
7} catch (e) {
TownieuseUser.tsx4 matches
8const [error, setError] = useState(null);
910const fetchData = async () => {
11try {
12const userEndpoint = new URL(USER_ENDPOINT, window.location.origin);
1314const res = await fetch(userEndpoint);
15const data = await res.json();
16if (!res.ok) {
3334useEffect(() => {
35fetchData();
36}, []);
3738return { data, loading, error, refetch: fetchData };
39}
40