@goldstack/template-ssr-server 0.1.10 → 0.3.1
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.
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda';
|
|
3
|
-
import type {
|
|
4
|
-
export type {
|
|
3
|
+
import type { BuildConfiguration, ServerBuildOptionsArgs, ClientBuildOptionsArgs } from '@goldstack/template-ssr-server-compile-bundle';
|
|
4
|
+
export type { BuildConfiguration, ServerBuildOptionsArgs, ClientBuildOptionsArgs, };
|
|
5
|
+
import { StaticFileMapper } from 'static-file-mapper';
|
|
5
6
|
export declare const clientBundleFileName = "client.bundle.js";
|
|
6
7
|
export declare const clientCSSFileName = "client.bundle.css";
|
|
7
|
-
export interface RenderDocumentProps {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export interface RenderDocumentProps<PropType> {
|
|
9
|
+
injectIntoHead: string;
|
|
10
|
+
injectIntoBody: string;
|
|
11
|
+
staticFileMapper: StaticFileMapper;
|
|
12
|
+
event: APIGatewayProxyEventV2;
|
|
13
|
+
properties: PropType;
|
|
14
|
+
}
|
|
15
|
+
export interface PartialRenderPageProps<PropType> {
|
|
16
|
+
entryPoint: string;
|
|
17
|
+
event: APIGatewayProxyEventV2;
|
|
18
|
+
renderDocument?: (props: RenderDocumentProps<PropType>) => string;
|
|
19
|
+
component: React.FunctionComponent<PropType>;
|
|
20
|
+
staticFileMapper?: StaticFileMapper;
|
|
21
|
+
staticFileMapperStore?: unknown;
|
|
22
|
+
properties: PropType;
|
|
23
|
+
buildConfig?: () => BuildConfiguration;
|
|
11
24
|
}
|
|
12
25
|
export interface RenderPageProps<PropType> {
|
|
13
26
|
entryPoint: string;
|
|
14
27
|
event: APIGatewayProxyEventV2;
|
|
15
|
-
renderDocument: (props: RenderDocumentProps) => string;
|
|
28
|
+
renderDocument: (props: RenderDocumentProps<PropType>) => string;
|
|
16
29
|
component: React.FunctionComponent<PropType>;
|
|
30
|
+
staticFileMapper?: StaticFileMapper;
|
|
31
|
+
staticFileMapperStore?: unknown;
|
|
17
32
|
properties: PropType;
|
|
18
|
-
|
|
33
|
+
buildConfig: () => BuildConfiguration;
|
|
19
34
|
}
|
|
20
|
-
export declare const renderPage: <PropType>({ entryPoint, event, renderDocument, component, properties,
|
|
35
|
+
export declare const renderPage: <PropType>({ entryPoint, event, renderDocument, staticFileMapper, staticFileMapperStore, component, properties, buildConfig, }: RenderPageProps<PropType>) => Promise<APIGatewayProxyResultV2>;
|
|
21
36
|
//# sourceMappingURL=templateSSRServer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateSSRServer.d.ts","sourceRoot":"","sources":["../../src/templateSSRServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"templateSSRServer.d.ts","sourceRoot":"","sources":["../../src/templateSSRServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAUpB,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACvB,MAAM,+CAA+C,CAAC;AAEvD,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,GACvB,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,eAAO,MAAM,oBAAoB,qBAAqB,CAAC;AACvD,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AAErD,MAAM,WAAW,mBAAmB,CAAC,QAAQ;IAC3C,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,KAAK,EAAE,sBAAsB,CAAC;IAC9B,UAAU,EAAE,QAAQ,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB,CAAC,QAAQ;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,sBAAsB,CAAC;IAC9B,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,CAAC,QAAQ,CAAC,KAAK,MAAM,CAAC;IAClE,SAAS,EAAE,KAAK,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC7C,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,UAAU,EAAE,QAAQ,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,kBAAkB,CAAC;CACxC;AAED,MAAM,WAAW,eAAe,CAAC,QAAQ;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,sBAAsB,CAAC;IAC9B,cAAc,EAAE,CAAC,KAAK,EAAE,mBAAmB,CAAC,QAAQ,CAAC,KAAK,MAAM,CAAC;IACjE,SAAS,EAAE,KAAK,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC7C,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,UAAU,EAAE,QAAQ,CAAC;IACrB,WAAW,EAAE,MAAM,kBAAkB,CAAC;CACvC;AAED,eAAO,MAAM,UAAU,gKASQ,QAAQ,uBAAuB,CAkG7D,CAAC"}
|
|
@@ -9,20 +9,38 @@ const lambda_compression_1 = require("lambda-compression");
|
|
|
9
9
|
const server_1 = require("react-dom/server");
|
|
10
10
|
const utils_esbuild_1 = require("@goldstack/utils-esbuild");
|
|
11
11
|
const fs_1 = require("fs");
|
|
12
|
+
const static_file_mapper_1 = require("static-file-mapper");
|
|
12
13
|
exports.clientBundleFileName = 'client.bundle.js';
|
|
13
14
|
exports.clientCSSFileName = 'client.bundle.css';
|
|
14
|
-
const renderPage = async ({ entryPoint, event, renderDocument, component, properties,
|
|
15
|
+
const renderPage = async ({ entryPoint, event, renderDocument, staticFileMapper, staticFileMapperStore, component, properties, buildConfig, }) => {
|
|
16
|
+
if (!staticFileMapper && !staticFileMapperStore) {
|
|
17
|
+
throw new Error('`staticFileMapper` or `staticFileMapper` store need to be defined for `renderPage`');
|
|
18
|
+
}
|
|
19
|
+
if (!staticFileMapper) {
|
|
20
|
+
staticFileMapper = new static_file_mapper_1.StaticFileMapperRun({
|
|
21
|
+
store: staticFileMapperStore,
|
|
22
|
+
baseUrl: '_goldstack/static/generated/',
|
|
23
|
+
});
|
|
24
|
+
}
|
|
15
25
|
if (event.queryStringParameters && event.queryStringParameters['resource']) {
|
|
16
26
|
if (event.queryStringParameters['resource'].indexOf('js') > -1) {
|
|
17
27
|
if (process.env.AWS_LAMBDA_FUNCTION_NAME) {
|
|
18
28
|
// if running in Lambda load bundle from local file system
|
|
29
|
+
let SourceMap = '';
|
|
30
|
+
if (await staticFileMapper.has({
|
|
31
|
+
name: `${process.env.AWS_LAMBDA_FUNCTION_NAME}.map`,
|
|
32
|
+
})) {
|
|
33
|
+
SourceMap = await staticFileMapper.resolve({
|
|
34
|
+
name: `${process.env.AWS_LAMBDA_FUNCTION_NAME}.map`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
19
37
|
return (0, lambda_compression_1.compress)(event, {
|
|
20
|
-
statusCode:
|
|
38
|
+
statusCode: 200,
|
|
21
39
|
headers: {
|
|
22
40
|
'Content-Type': 'application/javascript',
|
|
23
|
-
SourceMap
|
|
41
|
+
SourceMap,
|
|
24
42
|
},
|
|
25
|
-
body:
|
|
43
|
+
body: `${(0, fs_1.readFileSync)(exports.clientBundleFileName, 'utf-8')}`,
|
|
26
44
|
});
|
|
27
45
|
}
|
|
28
46
|
else {
|
|
@@ -31,28 +49,20 @@ const renderPage = async ({ entryPoint, event, renderDocument, component, proper
|
|
|
31
49
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
32
50
|
require((0, utils_esbuild_1.excludeInBundle)('@goldstack/template-ssr-server-compile-bundle')).bundleResponse({
|
|
33
51
|
entryPoint,
|
|
34
|
-
|
|
35
|
-
esbuildConfig: esbuildConfig(),
|
|
52
|
+
buildConfig: buildConfig(),
|
|
36
53
|
}));
|
|
37
54
|
}
|
|
38
55
|
}
|
|
39
56
|
if (event.queryStringParameters['resource'].indexOf('sourcemap') > -1) {
|
|
40
57
|
if (process.env.AWS_LAMBDA_FUNCTION_NAME) {
|
|
41
|
-
|
|
42
|
-
return (0, lambda_compression_1.compress)(event, {
|
|
43
|
-
statusCode: 201,
|
|
44
|
-
headers: {
|
|
45
|
-
'Content-Type': 'application/json',
|
|
46
|
-
},
|
|
47
|
-
body: (0, fs_1.readFileSync)(exports.clientBundleFileName + '.map', 'utf-8'),
|
|
48
|
-
});
|
|
58
|
+
throw new Error('sourcemap resource not supported in Lambda. Please load sourcemap from static files.');
|
|
49
59
|
}
|
|
50
60
|
else {
|
|
51
61
|
return (0, lambda_compression_1.compress)(event,
|
|
52
62
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
53
63
|
require((0, utils_esbuild_1.excludeInBundle)('@goldstack/template-ssr-server-compile-bundle')).sourceMapResponse({
|
|
54
64
|
entryPoint,
|
|
55
|
-
|
|
65
|
+
buildConfig: buildConfig(),
|
|
56
66
|
}));
|
|
57
67
|
}
|
|
58
68
|
}
|
|
@@ -67,12 +77,18 @@ const renderPage = async ({ entryPoint, event, renderDocument, component, proper
|
|
|
67
77
|
styles = undefined;
|
|
68
78
|
}
|
|
69
79
|
const document = renderDocument({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
80
|
+
injectIntoHead: `${styles ? `<style>${styles}</style>` : ''}`,
|
|
81
|
+
injectIntoBody: `
|
|
82
|
+
<div id="root">${page}</div>
|
|
83
|
+
<script>window.initialProperties=${JSON.stringify(properties)};</script>
|
|
84
|
+
<script src="?resource=js"></script>
|
|
85
|
+
`,
|
|
86
|
+
staticFileMapper: staticFileMapper,
|
|
87
|
+
event,
|
|
88
|
+
properties,
|
|
73
89
|
});
|
|
74
90
|
return (0, lambda_compression_1.compress)(event, {
|
|
75
|
-
statusCode:
|
|
91
|
+
statusCode: 200,
|
|
76
92
|
headers: {
|
|
77
93
|
'Content-Type': 'text/html',
|
|
78
94
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateSSRServer.js","sourceRoot":"","sources":["../../src/templateSSRServer.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAO1B,2DAA8C;AAE9C,6CAAkD;AAClD,4DAA2D;AAC3D,2BAAkC;
|
|
1
|
+
{"version":3,"file":"templateSSRServer.js","sourceRoot":"","sources":["../../src/templateSSRServer.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAO1B,2DAA8C;AAE9C,6CAAkD;AAClD,4DAA2D;AAC3D,2BAAkC;AAElC,2DAAuE;AAgB1D,QAAA,oBAAoB,GAAG,kBAAkB,CAAC;AAC1C,QAAA,iBAAiB,GAAG,mBAAmB,CAAC;AAgC9C,MAAM,UAAU,GAAG,KAAK,EAAY,EACzC,UAAU,EACV,KAAK,EACL,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,SAAS,EACT,UAAU,EACV,WAAW,GACe,EAAoC,EAAE;IAChE,IAAI,CAAC,gBAAgB,IAAI,CAAC,qBAAqB,EAAE;QAC/C,MAAM,IAAI,KAAK,CACb,oFAAoF,CACrF,CAAC;KACH;IACD,IAAI,CAAC,gBAAgB,EAAE;QACrB,gBAAgB,GAAG,IAAI,wCAAmB,CAAC;YACzC,KAAK,EAAE,qBAAqC;YAC5C,OAAO,EAAE,8BAA8B;SACxC,CAAC,CAAC;KACJ;IACD,IAAI,KAAK,CAAC,qBAAqB,IAAI,KAAK,CAAC,qBAAqB,CAAC,UAAU,CAAC,EAAE;QAC1E,IAAI,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,EACrB,+CAA+C,CAChD,CAAC,CAAC,iBAAiB,CAAC;oBACnB,UAAU;oBACV,WAAW,EAAE,WAAW,EAAE;iBAC3B,CAAC,CACH,CAAC;aACH;SACF;KACF;IAED,MAAM,IAAI,GAAG,IAAA,uBAAc,EAAC,eAAK,CAAC,aAAa,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;IAExE,IAAI,MAA0B,CAAC;IAC/B,4EAA4E;IAC5E,IAAI,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE;QACxC,MAAM,GAAG,IAAA,iBAAY,EAAC,yBAAiB,EAAE,OAAO,CAAC,CAAC;KACnD;SAAM;QACL,MAAM,GAAG,SAAS,CAAC;KACpB;IAED,MAAM,QAAQ,GAAG,cAAc,CAAC;QAC9B,cAAc,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,UAAU,MAAM,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE;QAC7D,cAAc,EAAE;yBACK,IAAI;2CACc,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;;KAEhE;QACD,gBAAgB,EAAE,gBAAgB;QAClC,KAAK;QACL,UAAU;KACX,CAAC,CAAC;IAEH,OAAO,IAAA,6BAAQ,EAAC,KAAK,EAAE;QACrB,UAAU,EAAE,GAAG;QACf,OAAO,EAAE;YACP,cAAc,EAAE,WAAW;SAC5B;QACD,IAAI,EAAE,QAAQ;KACf,CAAC,CAAC;AACL,CAAC,CAAC;AA3GW,QAAA,UAAU,cA2GrB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goldstack/template-ssr-server",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Building blocks for implementing server-side rendered pages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"goldstack",
|
|
@@ -38,25 +38,26 @@
|
|
|
38
38
|
"version:apply:force": "yarn version $@ && yarn version apply"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@goldstack/infra": "0.
|
|
42
|
-
"@goldstack/infra-aws": "0.
|
|
43
|
-
"@goldstack/template-ssr-server-compile-bundle": "0.1
|
|
44
|
-
"@goldstack/utils-aws-lambda": "0.1
|
|
45
|
-
"@goldstack/utils-esbuild": "0.
|
|
46
|
-
"@goldstack/utils-package": "0.
|
|
47
|
-
"@goldstack/utils-package-config-embedded": "0.
|
|
48
|
-
"@goldstack/utils-sh": "0.
|
|
49
|
-
"@goldstack/utils-template": "0.
|
|
50
|
-
"@goldstack/utils-terraform": "0.
|
|
51
|
-
"lambda-compression": "0.1
|
|
41
|
+
"@goldstack/infra": "0.4.1",
|
|
42
|
+
"@goldstack/infra-aws": "0.4.1",
|
|
43
|
+
"@goldstack/template-ssr-server-compile-bundle": "0.3.1",
|
|
44
|
+
"@goldstack/utils-aws-lambda": "0.3.1",
|
|
45
|
+
"@goldstack/utils-esbuild": "0.5.1",
|
|
46
|
+
"@goldstack/utils-package": "0.4.1",
|
|
47
|
+
"@goldstack/utils-package-config-embedded": "0.5.1",
|
|
48
|
+
"@goldstack/utils-sh": "0.5.1",
|
|
49
|
+
"@goldstack/utils-template": "0.4.1",
|
|
50
|
+
"@goldstack/utils-terraform": "0.4.1",
|
|
51
|
+
"lambda-compression": "0.2.1",
|
|
52
52
|
"react": "^18.2.0",
|
|
53
53
|
"react-dom": "^18.2.0",
|
|
54
|
-
"source-map-support": "^0.5.21"
|
|
54
|
+
"source-map-support": "^0.5.21",
|
|
55
|
+
"static-file-mapper": "0.3.1"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
58
|
"@goldstack/utils-docs-cli": "0.3.11",
|
|
58
|
-
"@goldstack/utils-git": "0.1
|
|
59
|
-
"@goldstack/utils-package-config-generate": "0.
|
|
59
|
+
"@goldstack/utils-git": "0.2.1",
|
|
60
|
+
"@goldstack/utils-package-config-generate": "0.3.1",
|
|
60
61
|
"@types/aws-lambda": "^8.10.88",
|
|
61
62
|
"@types/jest": "^28.1.8",
|
|
62
63
|
"@types/node": "^18.7.13",
|