Skip to content

Commit 69ad1cc

Browse files
committed
Proxy blocking node environment - fixed and closes #22
1 parent 1e0252b commit 69ad1cc

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lib/utils.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,23 @@ export function extractTime(timeRange: string, is24: boolean): string[] {
235235

236236
async function _fetchWebPage(pageUrl: string): Promise<string> {
237237
try {
238+
const fetchParams =
239+
typeof window !== "undefined" ?
240+
[
241+
`https://asia-south1-bonse-430603.cloudfunctions.net/rjs-proxy`,
242+
{
243+
method: "POST",
244+
headers: {
245+
"Content-Type": "application/json",
246+
},
247+
body: JSON.stringify({ url: pageUrl }),
248+
},
249+
]
250+
: [pageUrl, {}];
251+
238252
const response = await fetch(
239-
`https://asia-south1-bonse-430603.cloudfunctions.net/rjs-proxy`,
240-
{
241-
method: "POST",
242-
headers: {
243-
"Content-Type": "application/json",
244-
},
245-
body: JSON.stringify({ url: pageUrl }),
246-
},
253+
fetchParams[0] as string,
254+
fetchParams[1] as Record<string, any>,
247255
);
248256

249257
if (!response.ok) {

test/browser.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,4 @@ async function runAll() {
129129

130130
test("InAction (Browser) test", async () => {
131131
expect(await runAll()).toBe("passed");
132-
}, 30000);
132+
}, 60000);

0 commit comments

Comments
 (0)