Skip to content

Commit 87c1865

Browse files
authored
Merge pull request #219 from takker99:takker99/issue218
`location` is not available in Node.js environment
2 parents c939089 + 0400f86 commit 87c1865

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

websocket/findMetadata.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ export const findMetadata = (
6161

6262
const fileUrlPattern = new RegExp(
6363
`${
64-
location?.origin ?? "https://scrapbox.io"
65-
}/files/([a-z0-9]{24})(?:|\\.[a-zA-Z0-9]+)(?:|\\?[^\\s]*)$`,
64+
// For Node compatibility, we need to access `location` via `globalThis`
65+
// deno-lint-ignore no-explicit-any
66+
(globalThis as any).location?.origin ??
67+
"https://scrapbox.io"}/files/([a-z0-9]{24})(?:|\\.[a-zA-Z0-9]+)(?:|\\?[^\\s]*)$`,
6668
);
6769

6870
const lookup = (node: Node) => {

0 commit comments

Comments
 (0)