@quilted/quilt 0.5.65 → 0.5.68
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.
- package/CHANGELOG.md +20 -0
- package/build/cjs/server/http-handler.cjs +68 -68
- package/build/cjs/server/index.cjs +1 -0
- package/build/esm/server/http-handler.mjs +69 -70
- package/build/esm/server/index.mjs +1 -1
- package/build/esnext/server/http-handler.esnext +69 -70
- package/build/esnext/server/index.esnext +1 -1
- package/build/tsconfig.tsbuildinfo +1 -7512
- package/build/typescript/polyfills/crypto.d.ts +2 -0
- package/build/typescript/polyfills/crypto.d.ts.map +1 -0
- package/build/typescript/server/http-handler.d.ts +8 -6
- package/build/typescript/server/http-handler.d.ts.map +1 -1
- package/build/typescript/server/index.d.ts +1 -1
- package/build/typescript/server/index.d.ts.map +1 -1
- package/package.json +10 -1
- package/src/polyfills/crypto.ts +1 -0
- package/src/server/http-handler.tsx +72 -66
- package/src/server/index.ts +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/polyfills/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import type { ComponentType } from 'react';
|
|
1
|
+
import type { ComponentType, ReactElement } from 'react';
|
|
2
2
|
import type { AssetLoader } from '@quilted/async/server';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import type { Options as ExtractOptions } from '@quilted/react-server-render/server';
|
|
4
|
+
import type { Request, HttpHandler, RequestHandler } from '@quilted/http-handlers';
|
|
5
|
+
export interface Options<Props = Record<string, never>> extends ExtractOptions {
|
|
6
|
+
assets?: AssetLoader<unknown>;
|
|
6
7
|
handler?: HttpHandler;
|
|
7
8
|
renderProps?(options: {
|
|
8
9
|
request: Request;
|
|
9
10
|
}): Props;
|
|
10
11
|
}
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function createServerRenderingHttpHandler<Props>(App: ComponentType<Props>, { handler, ...options }: Options<Props>): HttpHandler;
|
|
13
|
+
export declare function createServerRenderingRequestHandler<Props>(App: ComponentType<Props>, { renderProps, ...options }?: Omit<Options<Props>, 'handler'>): RequestHandler;
|
|
14
|
+
export declare function renderToResponse<Props>(element: ReactElement<Props>, request: Request, { assets, ...options }?: Omit<Options<Props>, 'handler' | 'renderProps'>): Promise<import("@quilted/http-handlers").Response | undefined>;
|
|
13
15
|
//# sourceMappingURL=http-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-handler.d.ts","sourceRoot":"","sources":["../../../src/server/http-handler.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"http-handler.d.ts","sourceRoot":"","sources":["../../../src/server/http-handler.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,YAAY,EAAC,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EAAC,OAAO,IAAI,cAAc,EAAC,MAAM,qCAAqC,CAAC;AAGnF,OAAO,KAAK,EACV,OAAO,EACP,WAAW,EACX,cAAc,EACf,MAAM,wBAAwB,CAAC;AAIhC,MAAM,WAAW,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAE,SAAQ,cAAc;IAC5E,MAAM,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,WAAW,CAAC,CAAC,OAAO,EAAE;QAAC,OAAO,EAAE,OAAO,CAAA;KAAC,GAAG,KAAK,CAAC;CAClD;AAED,wBAAgB,gCAAgC,CAAC,KAAK,EACpD,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,EAAC,OAA6B,EAAE,GAAG,OAAO,EAAC,EAAE,OAAO,CAAC,KAAK,CAAC,eAI5D;AAED,wBAAgB,mCAAmC,CAAC,KAAK,EACvD,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,EAAC,WAAW,EAAE,GAAG,OAAO,EAAC,GAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,SAAS,CAAM,GAC9D,cAAc,CAQhB;AAED,wBAAsB,gBAAgB,CAAC,KAAK,EAC1C,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,EAC5B,OAAO,EAAE,OAAO,EAChB,EAAC,MAAM,EAAE,GAAG,OAAO,EAAC,GAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,SAAS,GAAG,aAAa,CAAM,kEAuD3E"}
|
|
@@ -9,5 +9,5 @@ export type { HttpState } from '@quilted/react-http/server';
|
|
|
9
9
|
export { createHttpHandler } from '@quilted/http-handlers';
|
|
10
10
|
export { renderApp } from './render';
|
|
11
11
|
export { ServerContext } from './ServerContext';
|
|
12
|
-
export { createServerRenderingRequestHandler, createServerRenderingHttpHandler, } from './http-handler';
|
|
12
|
+
export { createServerRenderingRequestHandler, createServerRenderingHttpHandler, renderToResponse, } from './http-handler';
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,IAAI,EACJ,SAAS,EACT,WAAW,EACX,WAAW,EACX,gBAAgB,IAAI,qBAAqB,GAC1C,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,OAAO,GACR,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AACxD,YAAY,EACV,KAAK,EACL,WAAW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AAiB,EAAC,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AACnC,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACL,mCAAmC,EACnC,gCAAgC,EAChC,gBAAgB,GACjB,MAAM,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quilted/quilt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.68",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/lemonmade/quilt.git",
|
|
@@ -103,6 +103,12 @@
|
|
|
103
103
|
"import": "./build/esm/polyfills/base.mjs",
|
|
104
104
|
"require": "./build/cjs/polyfills/base.cjs"
|
|
105
105
|
},
|
|
106
|
+
"./polyfills/crypto": {
|
|
107
|
+
"quilt:from-source": "./src/polyfills/crypto.ts",
|
|
108
|
+
"quilt:esnext": "./build/esnext/polyfills/crypto.esnext",
|
|
109
|
+
"import": "./build/esm/polyfills/crypto.mjs",
|
|
110
|
+
"require": "./build/cjs/polyfills/crypto.cjs"
|
|
111
|
+
},
|
|
106
112
|
"./polyfills/fetch": {
|
|
107
113
|
"quilt:from-source": "./src/polyfills/fetch.ts",
|
|
108
114
|
"quilt:esnext": "./build/esnext/polyfills/fetch.esnext",
|
|
@@ -167,6 +173,9 @@
|
|
|
167
173
|
"polyfills/fetch": [
|
|
168
174
|
"./build/typescript/polyfills/fetch.d.ts"
|
|
169
175
|
],
|
|
176
|
+
"polyfills/crypto": [
|
|
177
|
+
"./build/typescript/polyfills/crypto.d.ts"
|
|
178
|
+
],
|
|
170
179
|
"polyfills/noop": [
|
|
171
180
|
"./build/typescript/polyfills/noop.d.ts"
|
|
172
181
|
],
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@quilted/polyfills/crypto';
|
|
@@ -1,95 +1,101 @@
|
|
|
1
|
-
import type {ComponentType} from 'react';
|
|
1
|
+
import type {ComponentType, ReactElement} from 'react';
|
|
2
2
|
|
|
3
3
|
import type {AssetLoader} from '@quilted/async/server';
|
|
4
4
|
import {render as renderToString, Html} from '@quilted/react-html/server';
|
|
5
|
+
import type {Options as ExtractOptions} from '@quilted/react-server-render/server';
|
|
5
6
|
|
|
6
7
|
import {createHttpHandler, html, redirect} from '@quilted/http-handlers';
|
|
7
8
|
import type {
|
|
8
9
|
Request,
|
|
9
10
|
HttpHandler,
|
|
10
11
|
RequestHandler,
|
|
11
|
-
HttpHandlerOptions,
|
|
12
12
|
} from '@quilted/http-handlers';
|
|
13
13
|
|
|
14
14
|
import {renderApp} from './render';
|
|
15
15
|
|
|
16
|
-
export interface Options<Props = Record<string, never>>
|
|
17
|
-
|
|
18
|
-
assets: AssetLoader<unknown>;
|
|
16
|
+
export interface Options<Props = Record<string, never>> extends ExtractOptions {
|
|
17
|
+
assets?: AssetLoader<unknown>;
|
|
19
18
|
handler?: HttpHandler;
|
|
20
19
|
renderProps?(options: {request: Request}): Props;
|
|
21
20
|
}
|
|
22
21
|
|
|
22
|
+
export function createServerRenderingHttpHandler<Props>(
|
|
23
|
+
App: ComponentType<Props>,
|
|
24
|
+
{handler = createHttpHandler(), ...options}: Options<Props>,
|
|
25
|
+
) {
|
|
26
|
+
handler.get(createServerRenderingRequestHandler(App, options));
|
|
27
|
+
return handler;
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
export function createServerRenderingRequestHandler<Props>(
|
|
24
31
|
App: ComponentType<Props>,
|
|
25
|
-
{
|
|
26
|
-
assets,
|
|
27
|
-
renderProps = () => ({} as any),
|
|
28
|
-
}: Pick<Options<Props>, 'assets' | 'renderProps'>,
|
|
32
|
+
{renderProps, ...options}: Omit<Options<Props>, 'handler'> = {},
|
|
29
33
|
): RequestHandler {
|
|
30
|
-
return
|
|
31
|
-
|
|
34
|
+
return (request) => {
|
|
35
|
+
return renderToResponse(
|
|
36
|
+
<App {...(renderProps?.({request}) as any)} />,
|
|
37
|
+
request,
|
|
38
|
+
options,
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
32
42
|
|
|
33
|
-
|
|
43
|
+
export async function renderToResponse<Props>(
|
|
44
|
+
element: ReactElement<Props>,
|
|
45
|
+
request: Request,
|
|
46
|
+
{assets, ...options}: Omit<Options<Props>, 'handler' | 'renderProps'> = {},
|
|
47
|
+
) {
|
|
48
|
+
const accepts = request.headers.get('Accept');
|
|
34
49
|
|
|
35
|
-
|
|
36
|
-
html: htmlManager,
|
|
37
|
-
http,
|
|
38
|
-
markup,
|
|
39
|
-
asyncAssets,
|
|
40
|
-
} = await renderApp(<App {...renderProps?.({request})} />, {
|
|
41
|
-
url: request.url,
|
|
42
|
-
headers: request.headers,
|
|
43
|
-
});
|
|
50
|
+
if (accepts != null && !accepts.includes('text/html')) return;
|
|
44
51
|
|
|
45
|
-
|
|
52
|
+
const {
|
|
53
|
+
html: htmlManager,
|
|
54
|
+
http,
|
|
55
|
+
markup,
|
|
56
|
+
asyncAssets,
|
|
57
|
+
} = await renderApp(element, {
|
|
58
|
+
...options,
|
|
59
|
+
url: request.url,
|
|
60
|
+
headers: request.headers,
|
|
61
|
+
});
|
|
46
62
|
|
|
47
|
-
|
|
48
|
-
return redirect(redirectUrl, {
|
|
49
|
-
status: statusCode as 301,
|
|
50
|
-
headers,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
63
|
+
const {headers, statusCode = 200, redirectUrl} = http.state;
|
|
53
64
|
|
|
54
|
-
|
|
55
|
-
|
|
65
|
+
if (redirectUrl) {
|
|
66
|
+
return redirect(redirectUrl, {
|
|
67
|
+
status: statusCode as 301,
|
|
68
|
+
headers,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
56
71
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
assets.scripts({async: usedAssets, options: assetOptions}),
|
|
60
|
-
assets.asyncAssets(asyncAssets.used({timing: 'preload'}), {
|
|
61
|
-
options: assetOptions,
|
|
62
|
-
}),
|
|
63
|
-
]);
|
|
72
|
+
const usedAssets = asyncAssets.used({timing: 'load'});
|
|
73
|
+
const assetOptions = {userAgent: request.headers.get('User-Agent')};
|
|
64
74
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
</Html>,
|
|
75
|
-
),
|
|
76
|
-
{
|
|
77
|
-
headers,
|
|
78
|
-
status: statusCode,
|
|
79
|
-
},
|
|
80
|
-
);
|
|
81
|
-
};
|
|
82
|
-
}
|
|
75
|
+
const [styles, scripts, preload] = assets
|
|
76
|
+
? await Promise.all([
|
|
77
|
+
assets.styles({async: usedAssets, options: assetOptions}),
|
|
78
|
+
assets.scripts({async: usedAssets, options: assetOptions}),
|
|
79
|
+
assets.asyncAssets(asyncAssets.used({timing: 'preload'}), {
|
|
80
|
+
options: assetOptions,
|
|
81
|
+
}),
|
|
82
|
+
])
|
|
83
|
+
: [];
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
return html(
|
|
86
|
+
renderToString(
|
|
87
|
+
<Html
|
|
88
|
+
manager={htmlManager}
|
|
89
|
+
styles={styles}
|
|
90
|
+
scripts={scripts}
|
|
91
|
+
preloadAssets={preload}
|
|
92
|
+
>
|
|
93
|
+
{markup}
|
|
94
|
+
</Html>,
|
|
95
|
+
),
|
|
96
|
+
{
|
|
97
|
+
headers,
|
|
98
|
+
status: statusCode,
|
|
99
|
+
},
|
|
100
|
+
);
|
|
95
101
|
}
|