@quilted/create 0.2.42 → 0.2.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/build/esm/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/index.mjs +2 -2
  3. package/build/esm/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/providers/async.mjs +1 -1
  4. package/build/esm/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/providers/sync.mjs +1 -1
  5. package/build/esm/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/providers/async.mjs +1 -1
  6. package/build/esm/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/providers/stream.mjs +1 -1
  7. package/build/esm/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/providers/sync.mjs +1 -1
  8. package/build/esm/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/readers/async.mjs +1 -1
  9. package/build/esm/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/readers/sync.mjs +1 -1
  10. package/package.json +1 -1
  11. package/templates/app-basic/App.tsx +3 -4
  12. package/templates/app-basic/browser.tsx +5 -1
  13. package/templates/app-basic/foundation/html/Head.test.tsx +42 -0
  14. package/templates/app-basic/foundation/html/Head.tsx +34 -0
  15. package/templates/app-basic/foundation/html.ts +1 -1
  16. package/templates/app-basic/server.tsx +89 -3
  17. package/templates/app-empty/server.tsx +4 -3
  18. package/templates/app-graphql/App.tsx +3 -4
  19. package/templates/app-graphql/browser.tsx +5 -1
  20. package/templates/app-graphql/foundation/html/Head.test.tsx +42 -0
  21. package/templates/app-graphql/foundation/html/Head.tsx +34 -0
  22. package/templates/app-graphql/foundation/html.ts +1 -1
  23. package/templates/app-graphql/server.tsx +93 -9
  24. package/templates/app-trpc/App.tsx +3 -4
  25. package/templates/app-trpc/browser.tsx +5 -1
  26. package/templates/app-trpc/foundation/html/Head.test.tsx +42 -0
  27. package/templates/app-trpc/foundation/html/Head.tsx +34 -0
  28. package/templates/app-trpc/foundation/html.ts +1 -1
  29. package/templates/app-trpc/server.tsx +93 -8
  30. package/templates/app-basic/foundation/html/HTML.test.tsx +0 -46
  31. package/templates/app-basic/foundation/html/HTML.tsx +0 -159
  32. package/templates/app-graphql/foundation/html/HTML.test.tsx +0 -46
  33. package/templates/app-graphql/foundation/html/HTML.tsx +0 -159
  34. package/templates/app-trpc/foundation/html/HTML.test.tsx +0 -46
  35. package/templates/app-trpc/foundation/html/HTML.tsx +0 -159
@@ -0,0 +1,42 @@
1
+ import {describe, it, expect} from 'vitest';
2
+ import {Title, Favicon} from '@quilted/quilt/browser';
3
+ import {SearchRobots, Viewport} from '@quilted/quilt/server';
4
+
5
+ import {renderApp} from '~/tests/render.ts';
6
+
7
+ import {Head} from './Head.tsx';
8
+
9
+ describe('<Head />', () => {
10
+ it('sets the default title', async () => {
11
+ const head = await renderApp(<Head />);
12
+
13
+ expect(head).toContainPreactComponent(Title, {
14
+ children: 'App',
15
+ });
16
+ });
17
+
18
+ it('uses a fun, emoji favicon', async () => {
19
+ const head = await renderApp(<Head />);
20
+
21
+ expect(head).toContainPreactComponent(Favicon, {
22
+ emoji: '🧶',
23
+ });
24
+ });
25
+
26
+ it('includes a responsive viewport tag', async () => {
27
+ const head = await renderApp(<Head />);
28
+
29
+ expect(head).toContainPreactComponent(Viewport, {
30
+ cover: true,
31
+ });
32
+ });
33
+
34
+ it('prevents search robots from indexing the application', async () => {
35
+ const head = await renderApp(<Head />);
36
+
37
+ expect(head).toContainPreactComponent(SearchRobots, {
38
+ index: false,
39
+ follow: false,
40
+ });
41
+ });
42
+ });
@@ -0,0 +1,34 @@
1
+ import {Title, Favicon} from '@quilted/quilt/browser';
2
+ import {SearchRobots, Viewport} from '@quilted/quilt/server';
3
+
4
+ // This component sets default `<head>` details of the HTML page. If you need
5
+ // to customize any of these details based on conditions or application data, you
6
+ // can render these same components deeper in the application to override these defaults.
7
+ //
8
+ // @see https://github.com/lemonmade/quilt/blob/main/documentation/features/html.md
9
+ export function Head() {
10
+ return (
11
+ <>
12
+ {/* Sets the default `<title>` for this application. */}
13
+ <Title>App</Title>
14
+
15
+ {/*
16
+ * Sets the default favicon used by the application. You can
17
+ * change this to a different emoji, make it `blank`, or pass
18
+ * a URL with the `source` prop.
19
+ */}
20
+ <Favicon emoji="🧶" />
21
+
22
+ {/* Adds a responsive-friendly `viewport` `<meta>` tag. */}
23
+ <Viewport cover />
24
+
25
+ {/*
26
+ * Disables all search indexing for this application. If you are
27
+ * building an unauthenticated app, you probably want to remove
28
+ * this component, or update it to control how your site is indexed
29
+ * by search engines.
30
+ */}
31
+ <SearchRobots index={false} follow={false} />
32
+ </>
33
+ );
34
+ }
@@ -1 +1 @@
1
- export {HTML} from './html/HTML.tsx';
1
+ export {Head} from './html/Head.tsx';
@@ -1,5 +1,16 @@
1
1
  import '@quilted/quilt/globals';
2
+
2
3
  import {RequestRouter} from '@quilted/quilt/request-router';
4
+ import {Router} from '@quilted/quilt/navigation';
5
+ import {
6
+ renderAppToHTMLResponse,
7
+ cacheControlHeader,
8
+ contentSecurityPolicyHeader,
9
+ permissionsPolicyHeader,
10
+ strictTransportSecurityHeader,
11
+ } from '@quilted/quilt/server';
12
+
13
+ import Env from 'quilt:module/env';
3
14
  import {BrowserAssets} from 'quilt:module/assets';
4
15
 
5
16
  import {createDirectClient} from '@quilted/trpc/server';
@@ -27,13 +38,10 @@ router.any(
27
38
 
28
39
  // For all GET requests, render our React application.
29
40
  router.get(async (request) => {
30
- const [{App}, {renderToResponse}, {Router}, {QueryClient}] =
31
- await Promise.all([
32
- import('./App.tsx'),
33
- import('@quilted/quilt/server'),
34
- import('@quilted/quilt/navigation'),
35
- import('@tanstack/react-query'),
36
- ]);
41
+ const [{App}, {QueryClient}] = await Promise.all([
42
+ import('./App.tsx'),
43
+ import('@tanstack/react-query'),
44
+ ]);
37
45
 
38
46
  const context = {
39
47
  router: new Router(request.url),
@@ -41,9 +49,86 @@ router.get(async (request) => {
41
49
  queryClient: new QueryClient(),
42
50
  } satisfies AppContext;
43
51
 
44
- const response = await renderToResponse(<App context={context} />, {
52
+ const isHttps = request.url.startsWith('https://');
53
+
54
+ const response = await renderAppToHTMLResponse(<App context={context} />, {
45
55
  request,
46
56
  assets,
57
+ headers: {
58
+ // Controls how much information about the current page is included in
59
+ // requests (through the `Referer` header). The default value
60
+ // (strict-origin-when-cross-origin) means that only the origin is included
61
+ // for cross-origin requests, while the origin, path, and querystring
62
+ // are included for same-origin requests.
63
+ //
64
+ // @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
65
+ 'Referrer-Policy': 'strict-origin-when-cross-origin',
66
+
67
+ // Disables the cache for this page, which is generally the best option
68
+ // when dealing with authenticated content. If your site doesn't have
69
+ // authentication, or you have a better cache policy that works for your
70
+ // app or deployment, make sure to update this component accordingly!
71
+ //
72
+ // @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
73
+ 'Cache-Control': cacheControlHeader({
74
+ cache: false,
75
+ }),
76
+
77
+ // Sets a strict content security policy for this page. If you load
78
+ // assets from other origins, or want to allow some more dangerous
79
+ // resource loading techniques like `eval`, you can change the
80
+ // `defaultSources` to be less restrictive, or add additional items
81
+ // to the allowlist for more specific directives.
82
+ //
83
+ // @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
84
+ 'Content-Security-Policy': contentSecurityPolicyHeader({
85
+ // By default, only allow sources from the page's origin.
86
+ defaultSources: ["'self'"],
87
+ // In development, allow connections to local websockets for hot reloading.
88
+ connectSources:
89
+ Env.MODE === 'development'
90
+ ? ["'self'", `${isHttps ? 'ws' : 'wss'}://localhost:*`]
91
+ : undefined,
92
+ // Includes `'unsafe-inline'` because CSS is often necessary in development,
93
+ // and can be difficult to avoid in production.
94
+ styleSources: ["'self'", "'unsafe-inline'"],
95
+ // Includes `data:` so that an inline image can be used for the favicon.
96
+ // If you do not use the `emoji` or `blank` favicons in your app, and you
97
+ // do not load any other images as data URIs, you can remove this directive.
98
+ imageSources: ["'self'", 'data:'],
99
+ // Don't allow this page to be rendered as a frame from a different origin.
100
+ frameAncestors: false,
101
+ // Ensure that all requests made by this page are made over https, unless
102
+ // it is being served over http (typically, during local development)
103
+ upgradeInsecureRequests: isHttps,
104
+ }),
105
+
106
+ // Sets a strict permissions policy for this page, which limits access
107
+ // to some native browser features.
108
+ //
109
+ // @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
110
+ 'Permissions-Policy': permissionsPolicyHeader({
111
+ // Disables Google's Federated Learning of Cohorts ("FLoC") tracking initiative.
112
+ // @see https://www.eff.org/deeplinks/2021/03/googles-floc-terrible-idea
113
+ interestCohort: false,
114
+ // Don't use synchronous XHRs!
115
+ // @see https://featurepolicy.info/policies/sync-xhr
116
+ syncXhr: false,
117
+ // Disables access to a few device APIs that are infrequently used
118
+ // and prone to abuse. If your application uses these APIs intentionally,
119
+ // feel free to remove the prop, or pass an array containing the origins
120
+ // that should be allowed to use this feature (e.g., `['self']` to allow
121
+ // only the main page's origin).
122
+ camera: false,
123
+ microphone: false,
124
+ geolocation: false,
125
+ }),
126
+
127
+ // Instructs browsers to only load this page over HTTPS.
128
+ //
129
+ // @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security
130
+ 'Strict-Transport-Security': strictTransportSecurityHeader(),
131
+ },
47
132
  });
48
133
 
49
134
  return response;
@@ -1,46 +0,0 @@
1
- import {describe, it, expect} from 'vitest';
2
- import {
3
- CacheControl,
4
- ContentSecurityPolicy,
5
- SearchRobots,
6
- Viewport,
7
- } from '@quilted/quilt/server';
8
-
9
- import {renderApp} from '~/tests/render.ts';
10
-
11
- import {HTML} from './HTML.tsx';
12
-
13
- describe('<HTML />', () => {
14
- it('includes a responsive viewport tag', async () => {
15
- const head = await renderApp(<HTML />);
16
-
17
- expect(head).toContainPreactComponent(Viewport, {
18
- cover: true,
19
- });
20
- });
21
-
22
- it('prevents search robots from indexing the application', async () => {
23
- const head = await renderApp(<HTML />);
24
-
25
- expect(head).toContainPreactComponent(SearchRobots, {
26
- index: false,
27
- follow: false,
28
- });
29
- });
30
-
31
- it('does not cache the response', async () => {
32
- const headers = await renderApp(<HTML />);
33
-
34
- expect(headers).toContainPreactComponent(CacheControl, {
35
- cache: false,
36
- });
37
- });
38
-
39
- it('adds a content security policy with a strict default policy', async () => {
40
- const headers = await renderApp(<HTML />);
41
-
42
- expect(headers).toContainPreactComponent(ContentSecurityPolicy, {
43
- defaultSources: ["'self'"],
44
- });
45
- });
46
- });
@@ -1,159 +0,0 @@
1
- import type {RenderableProps} from 'preact';
2
- import Env from 'quilt:module/env';
3
- import {Title, Favicon, useBrowserRequest} from '@quilted/quilt/browser';
4
- import {
5
- CacheControl,
6
- ResponseHeader,
7
- ContentSecurityPolicy,
8
- PermissionsPolicy,
9
- SearchRobots,
10
- StrictTransportSecurity,
11
- Viewport,
12
- } from '@quilted/quilt/server';
13
-
14
- // This component sets details of the HTML page. If you need to customize
15
- // any of these details based on conditions like the active route, or some
16
- // state about the user, you can move these components to wherever in your
17
- // application you can read that state.
18
- //
19
- // @see https://github.com/lemonmade/quilt/blob/main/documentation/features/html.md
20
- export function HTML({children}: RenderableProps<{}>) {
21
- return (
22
- <>
23
- <Headers />
24
- <Head />
25
- {children}
26
- </>
27
- );
28
- }
29
-
30
- function Headers() {
31
- const {url} = useBrowserRequest();
32
- const isHttps = new URL(url).protocol === 'https:';
33
-
34
- return (
35
- <>
36
- {/*
37
- * Disables the cache for this page, which is generally the best option
38
- * when dealing with authenticated content. If your site doesn’t have
39
- * authentication, or you have a better cache policy that works for your
40
- * app or deployment, make sure to update this component accordingly!
41
- *
42
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
43
- */}
44
- <CacheControl cache={false} />
45
-
46
- {/*
47
- * Sets a strict content security policy for this page. If you load
48
- * assets from other origins, or want to allow some more dangerous
49
- * resource loading techniques like `eval`, you can change the
50
- * `defaultSources` to be less restrictive, or add additional items
51
- * to the allowlist for more specific directives.
52
- *
53
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
54
- */}
55
- <ContentSecurityPolicy
56
- reportOnly={Env.MODE === 'development'}
57
- // By default, only allow sources from the page’s origin.
58
- defaultSources={["'self'"]}
59
- // In development, allow connections to local websockets for hot reloading.
60
- connectSources={
61
- Env.MODE === 'development'
62
- ? ["'self'", `${isHttps ? 'ws' : 'wss'}://localhost:*`]
63
- : undefined
64
- }
65
- // Includes `'unsafe-inline'` because CSS is often necessary in development,
66
- // and can be difficult to avoid in production.
67
- styleSources={["'self'", "'unsafe-inline'"]}
68
- // Includes `data:` so that an inline image can be used for the favicon.
69
- // If you do not use the `emoji` or `blank` favicons in your app, and you
70
- // do not load any other images as data URIs, you can remove this directive.
71
- imageSources={["'self'", 'data:']}
72
- // Don’t allow this page to be rendered as a frame from a different origin.
73
- frameAncestors={false}
74
- // Ensure that all requests made by this page are made over https, unless
75
- // it is being served over http (typically, during local development)
76
- upgradeInsecureRequests={isHttps}
77
- />
78
-
79
- {/*
80
- * Sets a strict permissions policy for this page, which limits access
81
- * to some native browser features.
82
- *
83
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
84
- */}
85
- <PermissionsPolicy
86
- // Disables Google’s Federated Learning of Cohorts (“FLoC”) tracking initiative.
87
- // @see https://www.eff.org/deeplinks/2021/03/googles-floc-terrible-idea
88
- interestCohort={false}
89
- // Don’t use synchronous XHRs!
90
- // @see https://featurepolicy.info/policies/sync-xhr
91
- syncXhr={false}
92
- // Disables access to a few device APIs that are infrequently used
93
- // and prone to abuse. If your application uses these APIs intentionally,
94
- // feel free to remove the prop, or pass an array containing the origins
95
- // that should be allowed to use this feature (e.g., `['self']` to allow
96
- // only the main page’s origin).
97
- camera={false}
98
- microphone={false}
99
- geolocation={false}
100
- />
101
-
102
- {/*
103
- * Instructs browsers to only load this page over HTTPS using the
104
- * `Strict-Transport-Security` header.
105
- *
106
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security
107
- */}
108
- {isHttps && <StrictTransportSecurity />}
109
-
110
- {/*
111
- * Controls how much information about the current page is included in
112
- * requests (through the `Referer` header). The default value
113
- * (strict-origin-when-cross-origin) means that only the origin is included
114
- * for cross-origin requests, while the origin, path, and querystring
115
- * are included for same-origin requests.
116
- *
117
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
118
- */}
119
- <ResponseHeader
120
- name="Referrer-Policy"
121
- value="strict-origin-when-cross-origin"
122
- />
123
-
124
- {/*
125
- * Instructs browsers to respect the MIME type in the `Content-Type` header.
126
- *
127
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
128
- */}
129
- <ResponseHeader name="X-Content-Type-Options" value="nosniff" />
130
- </>
131
- );
132
- }
133
-
134
- function Head() {
135
- return (
136
- <>
137
- {/* Sets the default `<title>` for this application. */}
138
- <Title>App</Title>
139
-
140
- {/*
141
- * Sets the default favicon used by the application. You can
142
- * change this to a different emoji, make it `blank`, or pass
143
- * a URL with the `source` prop.
144
- */}
145
- <Favicon emoji="🧶" />
146
-
147
- {/* Adds a responsive-friendly `viewport` `<meta>` tag. */}
148
- <Viewport cover />
149
-
150
- {/*
151
- * Disables all search indexing for this application. If you are
152
- * building an unauthenticated app, you probably want to remove
153
- * this component, or update it to control how your site is indexed
154
- * by search engines.
155
- */}
156
- <SearchRobots index={false} follow={false} />
157
- </>
158
- );
159
- }
@@ -1,46 +0,0 @@
1
- import {describe, it, expect} from 'vitest';
2
- import {
3
- CacheControl,
4
- ContentSecurityPolicy,
5
- SearchRobots,
6
- Viewport,
7
- } from '@quilted/quilt/server';
8
-
9
- import {renderApp} from '~/tests/render.ts';
10
-
11
- import {HTML} from './HTML.tsx';
12
-
13
- describe('<HTML />', () => {
14
- it('includes a responsive viewport tag', async () => {
15
- const head = await renderApp(<HTML />);
16
-
17
- expect(head).toContainPreactComponent(Viewport, {
18
- cover: true,
19
- });
20
- });
21
-
22
- it('prevents search robots from indexing the application', async () => {
23
- const head = await renderApp(<HTML />);
24
-
25
- expect(head).toContainPreactComponent(SearchRobots, {
26
- index: false,
27
- follow: false,
28
- });
29
- });
30
-
31
- it('does not cache the response', async () => {
32
- const headers = await renderApp(<HTML />);
33
-
34
- expect(headers).toContainPreactComponent(CacheControl, {
35
- cache: false,
36
- });
37
- });
38
-
39
- it('adds a content security policy with a strict default policy', async () => {
40
- const headers = await renderApp(<HTML />);
41
-
42
- expect(headers).toContainPreactComponent(ContentSecurityPolicy, {
43
- defaultSources: ["'self'"],
44
- });
45
- });
46
- });
@@ -1,159 +0,0 @@
1
- import type {RenderableProps} from 'preact';
2
- import Env from 'quilt:module/env';
3
- import {Title, Favicon, useBrowserRequest} from '@quilted/quilt/browser';
4
- import {
5
- CacheControl,
6
- ResponseHeader,
7
- ContentSecurityPolicy,
8
- PermissionsPolicy,
9
- SearchRobots,
10
- StrictTransportSecurity,
11
- Viewport,
12
- } from '@quilted/quilt/server';
13
-
14
- // This component sets details of the HTML page. If you need to customize
15
- // any of these details based on conditions like the active route, or some
16
- // state about the user, you can move these components to wherever in your
17
- // application you can read that state.
18
- //
19
- // @see https://github.com/lemonmade/quilt/blob/main/documentation/features/html.md
20
- export function HTML({children}: RenderableProps<{}>) {
21
- return (
22
- <>
23
- <Headers />
24
- <Head />
25
- {children}
26
- </>
27
- );
28
- }
29
-
30
- function Headers() {
31
- const {url} = useBrowserRequest();
32
- const isHttps = new URL(url).protocol === 'https:';
33
-
34
- return (
35
- <>
36
- {/*
37
- * Disables the cache for this page, which is generally the best option
38
- * when dealing with authenticated content. If your site doesn’t have
39
- * authentication, or you have a better cache policy that works for your
40
- * app or deployment, make sure to update this component accordingly!
41
- *
42
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
43
- */}
44
- <CacheControl cache={false} />
45
-
46
- {/*
47
- * Sets a strict content security policy for this page. If you load
48
- * assets from other origins, or want to allow some more dangerous
49
- * resource loading techniques like `eval`, you can change the
50
- * `defaultSources` to be less restrictive, or add additional items
51
- * to the allowlist for more specific directives.
52
- *
53
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
54
- */}
55
- <ContentSecurityPolicy
56
- reportOnly={Env.MODE === 'development'}
57
- // By default, only allow sources from the page’s origin.
58
- defaultSources={["'self'"]}
59
- // In development, allow connections to local websockets for hot reloading.
60
- connectSources={
61
- Env.MODE === 'development'
62
- ? ["'self'", `${isHttps ? 'ws' : 'wss'}://localhost:*`]
63
- : undefined
64
- }
65
- // Includes `'unsafe-inline'` because CSS is often necessary in development,
66
- // and can be difficult to avoid in production.
67
- styleSources={["'self'", "'unsafe-inline'"]}
68
- // Includes `data:` so that an inline image can be used for the favicon.
69
- // If you do not use the `emoji` or `blank` favicons in your app, and you
70
- // do not load any other images as data URIs, you can remove this directive.
71
- imageSources={["'self'", 'data:']}
72
- // Don’t allow this page to be rendered as a frame from a different origin.
73
- frameAncestors={false}
74
- // Ensure that all requests made by this page are made over https, unless
75
- // it is being served over http (typically, during local development)
76
- upgradeInsecureRequests={isHttps}
77
- />
78
-
79
- {/*
80
- * Sets a strict permissions policy for this page, which limits access
81
- * to some native browser features.
82
- *
83
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
84
- */}
85
- <PermissionsPolicy
86
- // Disables Google’s Federated Learning of Cohorts (“FLoC”) tracking initiative.
87
- // @see https://www.eff.org/deeplinks/2021/03/googles-floc-terrible-idea
88
- interestCohort={false}
89
- // Don’t use synchronous XHRs!
90
- // @see https://featurepolicy.info/policies/sync-xhr
91
- syncXhr={false}
92
- // Disables access to a few device APIs that are infrequently used
93
- // and prone to abuse. If your application uses these APIs intentionally,
94
- // feel free to remove the prop, or pass an array containing the origins
95
- // that should be allowed to use this feature (e.g., `['self']` to allow
96
- // only the main page’s origin).
97
- camera={false}
98
- microphone={false}
99
- geolocation={false}
100
- />
101
-
102
- {/*
103
- * Instructs browsers to only load this page over HTTPS using the
104
- * `Strict-Transport-Security` header.
105
- *
106
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security
107
- */}
108
- {isHttps && <StrictTransportSecurity />}
109
-
110
- {/*
111
- * Controls how much information about the current page is included in
112
- * requests (through the `Referer` header). The default value
113
- * (strict-origin-when-cross-origin) means that only the origin is included
114
- * for cross-origin requests, while the origin, path, and querystring
115
- * are included for same-origin requests.
116
- *
117
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
118
- */}
119
- <ResponseHeader
120
- name="Referrer-Policy"
121
- value="strict-origin-when-cross-origin"
122
- />
123
-
124
- {/*
125
- * Instructs browsers to respect the MIME type in the `Content-Type` header.
126
- *
127
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
128
- */}
129
- <ResponseHeader name="X-Content-Type-Options" value="nosniff" />
130
- </>
131
- );
132
- }
133
-
134
- function Head() {
135
- return (
136
- <>
137
- {/* Sets the default `<title>` for this application. */}
138
- <Title>App</Title>
139
-
140
- {/*
141
- * Sets the default favicon used by the application. You can
142
- * change this to a different emoji, make it `blank`, or pass
143
- * a URL with the `source` prop.
144
- */}
145
- <Favicon emoji="🧶" />
146
-
147
- {/* Adds a responsive-friendly `viewport` `<meta>` tag. */}
148
- <Viewport cover />
149
-
150
- {/*
151
- * Disables all search indexing for this application. If you are
152
- * building an unauthenticated app, you probably want to remove
153
- * this component, or update it to control how your site is indexed
154
- * by search engines.
155
- */}
156
- <SearchRobots index={false} follow={false} />
157
- </>
158
- );
159
- }
@@ -1,46 +0,0 @@
1
- import {describe, it, expect} from 'vitest';
2
- import {
3
- CacheControl,
4
- ContentSecurityPolicy,
5
- SearchRobots,
6
- Viewport,
7
- } from '@quilted/quilt/server';
8
-
9
- import {renderApp} from '~/tests/render.ts';
10
-
11
- import {HTML} from './HTML.tsx';
12
-
13
- describe('<HTML />', () => {
14
- it('includes a responsive viewport tag', async () => {
15
- const head = await renderApp(<HTML />);
16
-
17
- expect(head).toContainPreactComponent(Viewport, {
18
- cover: true,
19
- });
20
- });
21
-
22
- it('prevents search robots from indexing the application', async () => {
23
- const head = await renderApp(<HTML />);
24
-
25
- expect(head).toContainPreactComponent(SearchRobots, {
26
- index: false,
27
- follow: false,
28
- });
29
- });
30
-
31
- it('does not cache the response', async () => {
32
- const headers = await renderApp(<HTML />);
33
-
34
- expect(headers).toContainPreactComponent(CacheControl, {
35
- cache: false,
36
- });
37
- });
38
-
39
- it('adds a content security policy with a strict default policy', async () => {
40
- const headers = await renderApp(<HTML />);
41
-
42
- expect(headers).toContainPreactComponent(ContentSecurityPolicy, {
43
- defaultSources: ["'self'"],
44
- });
45
- });
46
- });