Skip to content

Commit fc2c708

Browse files
committed
Serve CORS headers on the embed/script.js route
1 parent b77623b commit fc2c708

File tree

1 file changed

+15
-1
lines changed
  • packages/gitbook/src/app/sites/static/[mode]/[siteURL]/[siteData]/~gitbook/embed/script.js

1 file changed

+15
-1
lines changed

packages/gitbook/src/app/sites/static/[mode]/[siteURL]/[siteData]/~gitbook/embed/script.js/route.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import type { NextRequest } from 'next/server';
77

88
export const dynamic = 'force-static';
99

10+
const EMBEDDABLE_RESPONSE_HEADERS = {
11+
'Access-Control-Allow-Origin': '*',
12+
'Access-Control-Allow-Methods': 'GET, OPTIONS',
13+
'Cross-Origin-Resource-Policy': 'cross-origin',
14+
'Cache-Control': 'public, max-age=86400, stale-while-revalidate=604800',
15+
};
16+
1017
/**
1118
* This route is used to serve the assistant.js script.
1219
*/
@@ -69,9 +76,16 @@ export async function GET(
6976
`,
7077
{
7178
headers: {
79+
...EMBEDDABLE_RESPONSE_HEADERS,
7280
'Content-Type': 'application/javascript',
73-
'Cache-Control': 'public, max-age=86400, stale-while-revalidate=604800',
7481
},
7582
}
7683
);
7784
}
85+
86+
export function OPTIONS() {
87+
return new Response(null, {
88+
status: 204,
89+
headers: EMBEDDABLE_RESPONSE_HEADERS,
90+
});
91+
}

0 commit comments

Comments
 (0)