Skip to content

Commit a7e6b2c

Browse files
committed
fix: make edge function run locally
1 parent 59c2646 commit a7e6b2c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/helpers/setUpEdgeFunction.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,23 @@ const setUpEdgeFunction = async ({ angularJson, projectName, netlifyConfig, cons
5858
5959
globalThis.process = process
6060
globalThis.global = globalThis
61+
globalThis.DenoEvent = globalThis.Event // storing this for fixup-event.mjs
62+
`
63+
64+
// angular's polyfills override the global `Event` with a custom implementation.
65+
// Deno local doesn't like that and will throw in local dev while dispatching `new Event("load")`.
66+
// So we reverse angular's override, and go back to Deno's implementation.
67+
const fixupEvent = `
68+
globalThis.Event = globalThis.DenoEvent
6169
`
6270

6371
const ssrFunction = `
6472
import "./polyfill.mjs";
6573
import { Buffer } from "node:buffer";
6674
import { renderApplication } from "${toPosix(relative(edgeFunctionDir, serverDistRoot))}/render-utils.server.mjs";
6775
import bootstrap from "${toPosix(relative(edgeFunctionDir, serverDistRoot))}/main.server.mjs";
68-
76+
import "./fixup-event.mjs";
77+
6978
const document = Buffer.from(${JSON.stringify(
7079
Buffer.from(html, 'utf-8').toString('base64'),
7180
)}, 'base64').toString("utf-8");
@@ -88,6 +97,7 @@ const setUpEdgeFunction = async ({ angularJson, projectName, netlifyConfig, cons
8897
`
8998

9099
await writeFile(join(edgeFunctionDir, 'polyfill.mjs'), polyfills)
100+
await writeFile(join(edgeFunctionDir, 'fixup-event.mjs'), fixupEvent)
91101
await writeFile(join(edgeFunctionDir, 'angular-ssr.mjs'), ssrFunction)
92102
}
93103

0 commit comments

Comments
 (0)