From 20173e2db0087ff927a0ceadbdec71f18295cf51 Mon Sep 17 00:00:00 2001 From: PatrickJS Date: Wed, 23 Oct 2024 17:53:25 -0700 Subject: [PATCH] feat(main): allow for server/browser fetch --- lib/main.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/main.ts b/lib/main.ts index 5f9a65a..061aea8 100644 --- a/lib/main.ts +++ b/lib/main.ts @@ -3,12 +3,13 @@ import { RawFeedChannel, RawItem, SubstackItem } from "./types"; import { isRawFeed, isRawFeedChannel } from "./typeguards"; const CORS_PROXY = "https://corsproxy.io/?"; +const isBrowser = typeof document !== 'undefined'; // Internal API - const getRawXMLSubstackFeed = async (feedUrl: string) => { try { - const promise = await fetch(`${CORS_PROXY}${encodeURIComponent(feedUrl)}`); + const uri = isBrowser ? `${CORS_PROXY}${encodeURIComponent(feedUrl)}` : feedUrl; + const promise = await fetch(uri); if (promise.ok) return promise.text(); } catch (e) { throw new Error("Error occurred fetching Feed from Substack");