@quilted/quilt 0.5.66 → 0.5.69
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 +18 -0
- package/build/cjs/server/http-handler.cjs +68 -65
- package/build/cjs/server/index.cjs +1 -0
- package/build/esm/server/http-handler.mjs +69 -67
- package/build/esm/server/index.mjs +1 -1
- package/build/esnext/server/http-handler.esnext +69 -67
- package/build/esnext/server/index.esnext +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/server/http-handler.d.ts +7 -5
- 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 +1 -1
- package/src/server/http-handler.tsx +72 -59
- package/src/server/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @quilted/quilt
|
|
2
2
|
|
|
3
|
+
## 0.5.69
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`937a890`](https://github.com/lemonmade/quilt/commit/937a89009924a7b1d9e2a102028efd97928396e3) Thanks [@lemonmade](https://github.com/lemonmade)! - Improve base TypeScript preset
|
|
8
|
+
|
|
9
|
+
## 0.5.68
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`c4c6792`](https://github.com/lemonmade/quilt/commit/c4c6792ef355cc3bc8c8ada65ec7b1db8a836fef) Thanks [@lemonmade](https://github.com/lemonmade)! - Improve server rendering helpers
|
|
14
|
+
|
|
15
|
+
## 0.5.67
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [`ec90a3f`](https://github.com/lemonmade/quilt/commit/ec90a3f0de7366a42fd1e13b903154f5bc8c0a54) Thanks [@lemonmade](https://github.com/lemonmade)! - Add simpler way of rendering React to a http-handlers response
|
|
20
|
+
|
|
3
21
|
## 0.5.66
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -7,78 +7,81 @@ var httpHandlers = require('@quilted/http-handlers');
|
|
|
7
7
|
var render = require('./render.cjs');
|
|
8
8
|
var jsxRuntime = require('react/jsx-runtime');
|
|
9
9
|
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
function createServerRenderingHttpHandler(App, {
|
|
11
|
+
handler = httpHandlers.createHttpHandler(),
|
|
12
|
+
...options
|
|
13
13
|
}) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
handler.get(createServerRenderingRequestHandler(App, options));
|
|
15
|
+
return handler;
|
|
16
|
+
}
|
|
17
|
+
function createServerRenderingRequestHandler(App, {
|
|
18
|
+
renderProps,
|
|
19
|
+
...options
|
|
20
|
+
} = {}) {
|
|
21
|
+
return request => {
|
|
22
|
+
return renderToResponse( /*#__PURE__*/jsxRuntime.jsx(App, { ...renderProps?.({
|
|
23
23
|
request
|
|
24
24
|
})
|
|
25
|
-
}),
|
|
26
|
-
url: request.url,
|
|
27
|
-
headers: request.headers
|
|
28
|
-
});
|
|
29
|
-
const {
|
|
30
|
-
headers,
|
|
31
|
-
statusCode = 200,
|
|
32
|
-
redirectUrl
|
|
33
|
-
} = http.state;
|
|
34
|
-
|
|
35
|
-
if (redirectUrl) {
|
|
36
|
-
return httpHandlers.redirect(redirectUrl, {
|
|
37
|
-
status: statusCode,
|
|
38
|
-
headers
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const usedAssets = asyncAssets.used({
|
|
43
|
-
timing: 'load'
|
|
44
|
-
});
|
|
45
|
-
const assetOptions = {
|
|
46
|
-
userAgent: request.headers.get('User-Agent')
|
|
47
|
-
};
|
|
48
|
-
const [styles, scripts, preload] = await Promise.all([assets.styles({
|
|
49
|
-
async: usedAssets,
|
|
50
|
-
options: assetOptions
|
|
51
|
-
}), assets.scripts({
|
|
52
|
-
async: usedAssets,
|
|
53
|
-
options: assetOptions
|
|
54
|
-
}), assets.asyncAssets(asyncAssets.used({
|
|
55
|
-
timing: 'preload'
|
|
56
|
-
}), {
|
|
57
|
-
options: assetOptions
|
|
58
|
-
})]);
|
|
59
|
-
return httpHandlers.html(server.render( /*#__PURE__*/jsxRuntime.jsx(server.Html, {
|
|
60
|
-
manager: htmlManager,
|
|
61
|
-
styles: styles,
|
|
62
|
-
scripts: scripts,
|
|
63
|
-
preloadAssets: preload,
|
|
64
|
-
children: markup
|
|
65
|
-
})), {
|
|
66
|
-
headers,
|
|
67
|
-
status: statusCode
|
|
68
|
-
});
|
|
25
|
+
}), request, options);
|
|
69
26
|
};
|
|
70
27
|
}
|
|
71
|
-
function
|
|
28
|
+
async function renderToResponse(element, request, {
|
|
72
29
|
assets,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
30
|
+
...options
|
|
31
|
+
} = {}) {
|
|
32
|
+
const accepts = request.headers.get('Accept');
|
|
33
|
+
if (accepts != null && !accepts.includes('text/html')) return;
|
|
34
|
+
const {
|
|
35
|
+
html: htmlManager,
|
|
36
|
+
http,
|
|
37
|
+
markup,
|
|
38
|
+
asyncAssets
|
|
39
|
+
} = await render.renderApp(element, { ...options,
|
|
40
|
+
url: request.url,
|
|
41
|
+
headers: request.headers
|
|
42
|
+
});
|
|
43
|
+
const {
|
|
44
|
+
headers,
|
|
45
|
+
statusCode = 200,
|
|
46
|
+
redirectUrl
|
|
47
|
+
} = http.state;
|
|
48
|
+
|
|
49
|
+
if (redirectUrl) {
|
|
50
|
+
return httpHandlers.redirect(redirectUrl, {
|
|
51
|
+
status: statusCode,
|
|
52
|
+
headers
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const usedAssets = asyncAssets.used({
|
|
57
|
+
timing: 'load'
|
|
58
|
+
});
|
|
59
|
+
const assetOptions = {
|
|
60
|
+
userAgent: request.headers.get('User-Agent')
|
|
61
|
+
};
|
|
62
|
+
const [styles, scripts, preload] = assets ? await Promise.all([assets.styles({
|
|
63
|
+
async: usedAssets,
|
|
64
|
+
options: assetOptions
|
|
65
|
+
}), assets.scripts({
|
|
66
|
+
async: usedAssets,
|
|
67
|
+
options: assetOptions
|
|
68
|
+
}), assets.asyncAssets(asyncAssets.used({
|
|
69
|
+
timing: 'preload'
|
|
70
|
+
}), {
|
|
71
|
+
options: assetOptions
|
|
72
|
+
})]) : [];
|
|
73
|
+
return httpHandlers.html(server.render( /*#__PURE__*/jsxRuntime.jsx(server.Html, {
|
|
74
|
+
manager: htmlManager,
|
|
75
|
+
styles: styles,
|
|
76
|
+
scripts: scripts,
|
|
77
|
+
preloadAssets: preload,
|
|
78
|
+
children: markup
|
|
79
|
+
})), {
|
|
80
|
+
headers,
|
|
81
|
+
status: statusCode
|
|
82
|
+
});
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
exports.createServerRenderingHttpHandler = createServerRenderingHttpHandler;
|
|
84
86
|
exports.createServerRenderingRequestHandler = createServerRenderingRequestHandler;
|
|
87
|
+
exports.renderToResponse = renderToResponse;
|
|
@@ -86,3 +86,4 @@ exports.renderApp = render.renderApp;
|
|
|
86
86
|
exports.ServerContext = ServerContext.ServerContext;
|
|
87
87
|
exports.createServerRenderingHttpHandler = httpHandler.createServerRenderingHttpHandler;
|
|
88
88
|
exports.createServerRenderingRequestHandler = httpHandler.createServerRenderingRequestHandler;
|
|
89
|
+
exports.renderToResponse = httpHandler.renderToResponse;
|
|
@@ -1,79 +1,81 @@
|
|
|
1
1
|
import { render, Html } from '@quilted/react-html/server';
|
|
2
|
-
import { redirect, html
|
|
2
|
+
import { createHttpHandler, redirect, html } from '@quilted/http-handlers';
|
|
3
3
|
import { renderApp } from './render.mjs';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
function createServerRenderingHttpHandler(App, {
|
|
7
|
+
handler = createHttpHandler(),
|
|
8
|
+
...options
|
|
9
9
|
}) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
handler.get(createServerRenderingRequestHandler(App, options));
|
|
11
|
+
return handler;
|
|
12
|
+
}
|
|
13
|
+
function createServerRenderingRequestHandler(App, {
|
|
14
|
+
renderProps,
|
|
15
|
+
...options
|
|
16
|
+
} = {}) {
|
|
17
|
+
return request => {
|
|
18
|
+
return renderToResponse( /*#__PURE__*/jsx(App, { ...renderProps?.({
|
|
19
19
|
request
|
|
20
20
|
})
|
|
21
|
-
}),
|
|
22
|
-
url: request.url,
|
|
23
|
-
headers: request.headers
|
|
24
|
-
});
|
|
25
|
-
const {
|
|
26
|
-
headers,
|
|
27
|
-
statusCode = 200,
|
|
28
|
-
redirectUrl
|
|
29
|
-
} = http.state;
|
|
30
|
-
|
|
31
|
-
if (redirectUrl) {
|
|
32
|
-
return redirect(redirectUrl, {
|
|
33
|
-
status: statusCode,
|
|
34
|
-
headers
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const usedAssets = asyncAssets.used({
|
|
39
|
-
timing: 'load'
|
|
40
|
-
});
|
|
41
|
-
const assetOptions = {
|
|
42
|
-
userAgent: request.headers.get('User-Agent')
|
|
43
|
-
};
|
|
44
|
-
const [styles, scripts, preload] = await Promise.all([assets.styles({
|
|
45
|
-
async: usedAssets,
|
|
46
|
-
options: assetOptions
|
|
47
|
-
}), assets.scripts({
|
|
48
|
-
async: usedAssets,
|
|
49
|
-
options: assetOptions
|
|
50
|
-
}), assets.asyncAssets(asyncAssets.used({
|
|
51
|
-
timing: 'preload'
|
|
52
|
-
}), {
|
|
53
|
-
options: assetOptions
|
|
54
|
-
})]);
|
|
55
|
-
return html(render( /*#__PURE__*/jsx(Html, {
|
|
56
|
-
manager: htmlManager,
|
|
57
|
-
styles: styles,
|
|
58
|
-
scripts: scripts,
|
|
59
|
-
preloadAssets: preload,
|
|
60
|
-
children: markup
|
|
61
|
-
})), {
|
|
62
|
-
headers,
|
|
63
|
-
status: statusCode
|
|
64
|
-
});
|
|
21
|
+
}), request, options);
|
|
65
22
|
};
|
|
66
23
|
}
|
|
67
|
-
function
|
|
24
|
+
async function renderToResponse(element, request, {
|
|
68
25
|
assets,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
26
|
+
...options
|
|
27
|
+
} = {}) {
|
|
28
|
+
const accepts = request.headers.get('Accept');
|
|
29
|
+
if (accepts != null && !accepts.includes('text/html')) return;
|
|
30
|
+
const {
|
|
31
|
+
html: htmlManager,
|
|
32
|
+
http,
|
|
33
|
+
markup,
|
|
34
|
+
asyncAssets
|
|
35
|
+
} = await renderApp(element, { ...options,
|
|
36
|
+
url: request.url,
|
|
37
|
+
headers: request.headers
|
|
38
|
+
});
|
|
39
|
+
const {
|
|
40
|
+
headers,
|
|
41
|
+
statusCode = 200,
|
|
42
|
+
redirectUrl
|
|
43
|
+
} = http.state;
|
|
44
|
+
|
|
45
|
+
if (redirectUrl) {
|
|
46
|
+
return redirect(redirectUrl, {
|
|
47
|
+
status: statusCode,
|
|
48
|
+
headers
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const usedAssets = asyncAssets.used({
|
|
53
|
+
timing: 'load'
|
|
54
|
+
});
|
|
55
|
+
const assetOptions = {
|
|
56
|
+
userAgent: request.headers.get('User-Agent')
|
|
57
|
+
};
|
|
58
|
+
const [styles, scripts, preload] = assets ? await Promise.all([assets.styles({
|
|
59
|
+
async: usedAssets,
|
|
60
|
+
options: assetOptions
|
|
61
|
+
}), assets.scripts({
|
|
62
|
+
async: usedAssets,
|
|
63
|
+
options: assetOptions
|
|
64
|
+
}), assets.asyncAssets(asyncAssets.used({
|
|
65
|
+
timing: 'preload'
|
|
66
|
+
}), {
|
|
67
|
+
options: assetOptions
|
|
68
|
+
})]) : [];
|
|
69
|
+
return html(render( /*#__PURE__*/jsx(Html, {
|
|
70
|
+
manager: htmlManager,
|
|
71
|
+
styles: styles,
|
|
72
|
+
scripts: scripts,
|
|
73
|
+
preloadAssets: preload,
|
|
74
|
+
children: markup
|
|
75
|
+
})), {
|
|
76
|
+
headers,
|
|
77
|
+
status: statusCode
|
|
78
|
+
});
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
export { createServerRenderingHttpHandler, createServerRenderingRequestHandler };
|
|
81
|
+
export { createServerRenderingHttpHandler, createServerRenderingRequestHandler, renderToResponse };
|
|
@@ -6,4 +6,4 @@ export { renderEmail } from '@quilted/react-email/server';
|
|
|
6
6
|
export { createHttpHandler } from '@quilted/http-handlers';
|
|
7
7
|
export { renderApp } from './render.mjs';
|
|
8
8
|
export { ServerContext } from './ServerContext.mjs';
|
|
9
|
-
export { createServerRenderingHttpHandler, createServerRenderingRequestHandler } from './http-handler.mjs';
|
|
9
|
+
export { createServerRenderingHttpHandler, createServerRenderingRequestHandler, renderToResponse } from './http-handler.mjs';
|
|
@@ -1,79 +1,81 @@
|
|
|
1
1
|
import { render, Html } from '@quilted/react-html/server';
|
|
2
|
-
import { redirect, html
|
|
2
|
+
import { createHttpHandler, redirect, html } from '@quilted/http-handlers';
|
|
3
3
|
import { renderApp } from './render.esnext';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
function createServerRenderingHttpHandler(App, {
|
|
7
|
+
handler = createHttpHandler(),
|
|
8
|
+
...options
|
|
9
9
|
}) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
handler.get(createServerRenderingRequestHandler(App, options));
|
|
11
|
+
return handler;
|
|
12
|
+
}
|
|
13
|
+
function createServerRenderingRequestHandler(App, {
|
|
14
|
+
renderProps,
|
|
15
|
+
...options
|
|
16
|
+
} = {}) {
|
|
17
|
+
return request => {
|
|
18
|
+
return renderToResponse( /*#__PURE__*/jsx(App, { ...renderProps?.({
|
|
19
19
|
request
|
|
20
20
|
})
|
|
21
|
-
}),
|
|
22
|
-
url: request.url,
|
|
23
|
-
headers: request.headers
|
|
24
|
-
});
|
|
25
|
-
const {
|
|
26
|
-
headers,
|
|
27
|
-
statusCode = 200,
|
|
28
|
-
redirectUrl
|
|
29
|
-
} = http.state;
|
|
30
|
-
|
|
31
|
-
if (redirectUrl) {
|
|
32
|
-
return redirect(redirectUrl, {
|
|
33
|
-
status: statusCode,
|
|
34
|
-
headers
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const usedAssets = asyncAssets.used({
|
|
39
|
-
timing: 'load'
|
|
40
|
-
});
|
|
41
|
-
const assetOptions = {
|
|
42
|
-
userAgent: request.headers.get('User-Agent')
|
|
43
|
-
};
|
|
44
|
-
const [styles, scripts, preload] = await Promise.all([assets.styles({
|
|
45
|
-
async: usedAssets,
|
|
46
|
-
options: assetOptions
|
|
47
|
-
}), assets.scripts({
|
|
48
|
-
async: usedAssets,
|
|
49
|
-
options: assetOptions
|
|
50
|
-
}), assets.asyncAssets(asyncAssets.used({
|
|
51
|
-
timing: 'preload'
|
|
52
|
-
}), {
|
|
53
|
-
options: assetOptions
|
|
54
|
-
})]);
|
|
55
|
-
return html(render( /*#__PURE__*/jsx(Html, {
|
|
56
|
-
manager: htmlManager,
|
|
57
|
-
styles: styles,
|
|
58
|
-
scripts: scripts,
|
|
59
|
-
preloadAssets: preload,
|
|
60
|
-
children: markup
|
|
61
|
-
})), {
|
|
62
|
-
headers,
|
|
63
|
-
status: statusCode
|
|
64
|
-
});
|
|
21
|
+
}), request, options);
|
|
65
22
|
};
|
|
66
23
|
}
|
|
67
|
-
function
|
|
24
|
+
async function renderToResponse(element, request, {
|
|
68
25
|
assets,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
26
|
+
...options
|
|
27
|
+
} = {}) {
|
|
28
|
+
const accepts = request.headers.get('Accept');
|
|
29
|
+
if (accepts != null && !accepts.includes('text/html')) return;
|
|
30
|
+
const {
|
|
31
|
+
html: htmlManager,
|
|
32
|
+
http,
|
|
33
|
+
markup,
|
|
34
|
+
asyncAssets
|
|
35
|
+
} = await renderApp(element, { ...options,
|
|
36
|
+
url: request.url,
|
|
37
|
+
headers: request.headers
|
|
38
|
+
});
|
|
39
|
+
const {
|
|
40
|
+
headers,
|
|
41
|
+
statusCode = 200,
|
|
42
|
+
redirectUrl
|
|
43
|
+
} = http.state;
|
|
44
|
+
|
|
45
|
+
if (redirectUrl) {
|
|
46
|
+
return redirect(redirectUrl, {
|
|
47
|
+
status: statusCode,
|
|
48
|
+
headers
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const usedAssets = asyncAssets.used({
|
|
53
|
+
timing: 'load'
|
|
54
|
+
});
|
|
55
|
+
const assetOptions = {
|
|
56
|
+
userAgent: request.headers.get('User-Agent')
|
|
57
|
+
};
|
|
58
|
+
const [styles, scripts, preload] = assets ? await Promise.all([assets.styles({
|
|
59
|
+
async: usedAssets,
|
|
60
|
+
options: assetOptions
|
|
61
|
+
}), assets.scripts({
|
|
62
|
+
async: usedAssets,
|
|
63
|
+
options: assetOptions
|
|
64
|
+
}), assets.asyncAssets(asyncAssets.used({
|
|
65
|
+
timing: 'preload'
|
|
66
|
+
}), {
|
|
67
|
+
options: assetOptions
|
|
68
|
+
})]) : [];
|
|
69
|
+
return html(render( /*#__PURE__*/jsx(Html, {
|
|
70
|
+
manager: htmlManager,
|
|
71
|
+
styles: styles,
|
|
72
|
+
scripts: scripts,
|
|
73
|
+
preloadAssets: preload,
|
|
74
|
+
children: markup
|
|
75
|
+
})), {
|
|
76
|
+
headers,
|
|
77
|
+
status: statusCode
|
|
78
|
+
});
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
export { createServerRenderingHttpHandler, createServerRenderingRequestHandler };
|
|
81
|
+
export { createServerRenderingHttpHandler, createServerRenderingRequestHandler, renderToResponse };
|
|
@@ -6,4 +6,4 @@ export { renderEmail } from '@quilted/react-email/server';
|
|
|
6
6
|
export { createHttpHandler } from '@quilted/http-handlers';
|
|
7
7
|
export { renderApp } from './render.esnext';
|
|
8
8
|
export { ServerContext } from './ServerContext.esnext';
|
|
9
|
-
export { createServerRenderingHttpHandler, createServerRenderingRequestHandler } from './http-handler.esnext';
|
|
9
|
+
export { createServerRenderingHttpHandler, createServerRenderingRequestHandler, renderToResponse } from './http-handler.esnext';
|