Skip to content

Commit bedf4b1

Browse files
committed
Fix external CORS
1 parent 749df3d commit bedf4b1

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/index.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,27 @@ router.post(
4646
const context = await browser.newContext({
4747
...defaultContext,
4848
colorScheme: body.theme,
49-
extraHTTPHeaders: body.headers,
5049
});
50+
51+
// await context.tracing.start({ screenshots: true, snapshots: true });
52+
5153
const page = await context.newPage();
54+
55+
// Override headers
56+
await page.route("**/*", async (route, request) => {
57+
const url = request.url();
58+
if (url.startsWith("http://appwrite/")) {
59+
return await route.continue({
60+
headers: {
61+
...request.headers(),
62+
...body.headers,
63+
},
64+
});
65+
}
66+
67+
return await route.continue({ headers: request.headers() });
68+
});
69+
5270
await page.goto(body.url, {
5371
waitUntil: "domcontentloaded",
5472
});
@@ -58,6 +76,9 @@ router.post(
5876
}
5977

6078
const screen = await page.screenshot();
79+
80+
// await context.tracing.stop({ path: '/tmp/trace' + Date.now() + '.zip' });
81+
6182
await context.close();
6283
return screen;
6384
}),

0 commit comments

Comments
 (0)