Skip to content

Commit 0f330d5

Browse files
committed
Add test
1 parent 91b9c79 commit 0f330d5

File tree

2 files changed

+38
-7
lines changed
  • packages/gitbook

2 files changed

+38
-7
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,3 @@ export async function GET(
8282
}
8383
);
8484
}
85-
86-
export function OPTIONS() {
87-
return new Response(null, {
88-
status: 204,
89-
headers: EMBEDDABLE_RESPONSE_HEADERS,
90-
});
91-
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { describe, expect, it } from 'bun:test';
2+
import { getContentTestURL } from './utils';
3+
4+
const EMBED_SCRIPT_URL = getContentTestURL(
5+
'https://gitbook.gitbook.io/test-gitbook-open/~gitbook/embed/script.js'
6+
);
7+
8+
describe('embed script', () => {
9+
it('serves the embeddable script with permissive headers', async () => {
10+
const response = await fetch(EMBED_SCRIPT_URL, {
11+
headers: {
12+
Origin: 'https://example.com',
13+
},
14+
});
15+
16+
expect(response.status).toBe(200);
17+
expect(response.headers.get('content-type')).toContain('application/javascript');
18+
expect(response.headers.get('access-control-allow-origin')).toBe('*');
19+
expect(response.headers.get('cross-origin-resource-policy')).toBe('cross-origin');
20+
21+
const body = await response.text();
22+
expect(body).toContain('w.GitBook');
23+
});
24+
25+
it('responds to OPTIONS requests with CORS headers for cross-domain insertion', async () => {
26+
const response = await fetch(EMBED_SCRIPT_URL, {
27+
method: 'OPTIONS',
28+
headers: {
29+
Origin: 'https://example.com',
30+
'Access-Control-Request-Method': 'GET',
31+
},
32+
});
33+
34+
expect(response.status).toBe(204);
35+
expect(response.headers.get('access-control-allow-origin')).toBe('*');
36+
expect(response.headers.get('access-control-allow-methods')).toContain('GET');
37+
});
38+
});

0 commit comments

Comments
 (0)