|
1 | 1 | import { |
2 | | - createIntegration, |
3 | | - FetchEventCallback, |
4 | | - FetchPublishScriptEventCallback, |
5 | | - RuntimeContext, |
6 | | - RuntimeEnvironment |
7 | | -} from '@gitbook/runtime' |
8 | | -import { VoteBlock } from './vote-block' |
| 2 | + createIntegration, |
| 3 | + FetchEventCallback, |
| 4 | + FetchPublishScriptEventCallback, |
| 5 | + RuntimeContext, |
| 6 | + RuntimeEnvironment, |
| 7 | +} from '@gitbook/runtime'; |
| 8 | +import { VoteBlock } from './vote-block'; |
9 | 9 |
|
10 | 10 | // @ts-ignore |
11 | 11 | // eslint-disable-next-line import/no-unresolved |
12 | | -import script from './script.raw.js?raw' // the generated string module |
| 12 | +import script from './script.raw.js?raw'; // the generated string module |
13 | 13 |
|
14 | 14 | type VaultriceContext = RuntimeContext< |
15 | | - RuntimeEnvironment< |
16 | | - {}, |
17 | | - { |
18 | | - projectId?: string; |
19 | | - apiKey?: string; |
20 | | - apiSecret?: string; |
21 | | - } |
22 | | - > |
23 | | -> |
| 15 | + RuntimeEnvironment< |
| 16 | + {}, |
| 17 | + { |
| 18 | + projectId?: string; |
| 19 | + apiKey?: string; |
| 20 | + apiSecret?: string; |
| 21 | + } |
| 22 | + > |
| 23 | +>; |
24 | 24 |
|
25 | 25 | /** |
26 | 26 | * serve the published script: return JS string with placeholders replaced |
27 | 27 | */ |
28 | | -export const handleFetchPublishedScript: FetchPublishScriptEventCallback = async (event, { environment }: VaultriceContext) => { |
29 | | - return new Response(script as string, { |
30 | | - headers: { |
31 | | - 'Content-Type': 'application/javascript', |
32 | | - 'Cache-Control': 'public, max-age=3600' |
33 | | - } |
34 | | - }) |
35 | | -} |
| 28 | +export const handleFetchPublishedScript: FetchPublishScriptEventCallback = async ( |
| 29 | + event, |
| 30 | + { environment }: VaultriceContext, |
| 31 | +) => { |
| 32 | + return new Response(script as string, { |
| 33 | + headers: { |
| 34 | + 'Content-Type': 'application/javascript', |
| 35 | + 'Cache-Control': 'public, max-age=3600', |
| 36 | + }, |
| 37 | + }); |
| 38 | +}; |
36 | 39 |
|
37 | 40 | /** |
38 | 41 | * Generic HTTP handler (GitBook calls /integration) |
39 | 42 | */ |
40 | 43 | export const handleFetch: FetchEventCallback = async (request, context) => { |
41 | | - const url = new URL(request.url) |
42 | | - const path = url.pathname |
| 44 | + const url = new URL(request.url); |
| 45 | + const path = url.pathname; |
43 | 46 |
|
44 | | - if (path.endsWith('voting.js') && url.searchParams.get('script') === 'true') { |
45 | | - return handleFetchPublishedScript(request as any, context as any) as any |
46 | | - } |
| 47 | + if (path.endsWith('voting.js') && url.searchParams.get('script') === 'true') { |
| 48 | + return handleFetchPublishedScript(request as any, context as any) as any; |
| 49 | + } |
47 | 50 |
|
48 | | - return new Response( |
49 | | - `<!doctype html> |
| 51 | + return new Response( |
| 52 | + `<!doctype html> |
50 | 53 | <html> |
51 | 54 | <head> |
52 | 55 | <meta charset="utf-8" /> |
@@ -76,17 +79,17 @@ export const handleFetch: FetchEventCallback = async (request, context) => { |
76 | 79 | </script> |
77 | 80 | </body> |
78 | 81 | </html>`, |
79 | | - { |
80 | | - headers: { |
81 | | - 'Content-Type': 'text/html', |
82 | | - 'Cache-Control': 'public, max-age=86400' |
83 | | - }, |
84 | | - } |
85 | | - ) |
86 | | -} |
| 82 | + { |
| 83 | + headers: { |
| 84 | + 'Content-Type': 'text/html', |
| 85 | + 'Cache-Control': 'public, max-age=86400', |
| 86 | + }, |
| 87 | + }, |
| 88 | + ); |
| 89 | +}; |
87 | 90 |
|
88 | 91 | export default createIntegration({ |
89 | | - fetch: handleFetch, |
90 | | - fetch_published_script: handleFetchPublishedScript, |
91 | | - components: [VoteBlock] |
92 | | -}) |
| 92 | + fetch: handleFetch, |
| 93 | + fetch_published_script: handleFetchPublishedScript, |
| 94 | + components: [VoteBlock], |
| 95 | +}); |
0 commit comments