Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down