@goldstack/template-ssr-server 0.1.11 → 0.3.0
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.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { APIGatewayProxyResultV2 } from 'aws-lambda';
|
|
2
|
+
export interface CompileBundleResponse {
|
|
3
|
+
bundle: string;
|
|
4
|
+
sourceMap?: string;
|
|
5
|
+
metaFile?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const compileBundle: ({ entryPoint, metaFile, sourceMap, initialProperties, includeCss, }: {
|
|
8
|
+
entryPoint: string;
|
|
9
|
+
metaFile?: boolean | undefined;
|
|
10
|
+
sourceMap?: boolean | undefined;
|
|
11
|
+
initialProperties?: any;
|
|
12
|
+
includeCss: boolean;
|
|
13
|
+
}) => Promise<CompileBundleResponse>;
|
|
14
|
+
export declare const bundleResponse: ({ entryPoint, initialProperties, }: {
|
|
15
|
+
entryPoint: string;
|
|
16
|
+
initialProperties?: any;
|
|
17
|
+
}) => Promise<APIGatewayProxyResultV2>;
|
|
18
|
+
export declare const sourceMapResponse: ({ entryPoint, }: {
|
|
19
|
+
entryPoint: string;
|
|
20
|
+
}) => Promise<APIGatewayProxyResultV2>;
|
|
21
|
+
//# sourceMappingURL=compileBundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compileBundle.d.ts","sourceRoot":"","sources":["../../src/compileBundle.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAoCrD,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAsBD,eAAO,MAAM,aAAa;gBAOZ,MAAM;;;wBAGE,GAAG;gBACX,OAAO;MACjB,QAAQ,qBAAqB,CAyChC,CAAC;AAEF,eAAO,MAAM,cAAc;gBAIb,MAAM;wBACE,GAAG;MACrB,QAAQ,uBAAuB,CAkBlC,CAAC;AAoBF,eAAO,MAAM,iBAAiB;gBAGhB,MAAM;MAChB,QAAQ,uBAAuB,CAsBlC,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sourceMapResponse = exports.bundleResponse = exports.compileBundle = void 0;
|
|
7
|
+
const esbuild_1 = require("esbuild");
|
|
8
|
+
const esbuild_plugin_pnp_1 = require("@yarnpkg/esbuild-plugin-pnp");
|
|
9
|
+
const esbuild_css_modules_client_plugin_1 = __importDefault(require("esbuild-css-modules-client-plugin"));
|
|
10
|
+
const utils_sh_1 = require("@goldstack/utils-sh");
|
|
11
|
+
const path_1 = require("path");
|
|
12
|
+
const sharedConfig = (includeCss) => {
|
|
13
|
+
return {
|
|
14
|
+
plugins: [
|
|
15
|
+
(0, esbuild_css_modules_client_plugin_1.default)({
|
|
16
|
+
excludeCSSInject: !includeCss,
|
|
17
|
+
}),
|
|
18
|
+
(0, esbuild_plugin_pnp_1.pnpPlugin)(),
|
|
19
|
+
],
|
|
20
|
+
bundle: true,
|
|
21
|
+
outfile: '/dist/tmp/bundle.js',
|
|
22
|
+
external: [
|
|
23
|
+
'esbuild',
|
|
24
|
+
'@yarnpkg/esbuild-plugin-pnp',
|
|
25
|
+
'@goldstack/template-ssr-server', // this is only required on the server side
|
|
26
|
+
],
|
|
27
|
+
minify: true,
|
|
28
|
+
platform: 'browser',
|
|
29
|
+
format: 'iife',
|
|
30
|
+
treeShaking: true,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const getEsBuildConfig = (entryPoint) => {
|
|
34
|
+
const esbuildConfig = (0, utils_sh_1.readToType)('./esbuild.config.json');
|
|
35
|
+
const esbuildLocalPath = (0, utils_sh_1.changeExtension)((0, path_1.dirname)(entryPoint), '.esbuild.config.json');
|
|
36
|
+
const localEsbuildConfig = (0, utils_sh_1.readToType)(esbuildLocalPath);
|
|
37
|
+
return { ...esbuildConfig, ...localEsbuildConfig };
|
|
38
|
+
};
|
|
39
|
+
const getOutput = (extension, result) => {
|
|
40
|
+
const matchedFiles = result.outputFiles.filter((file) => file.path.endsWith(extension));
|
|
41
|
+
if (matchedFiles.length !== 1) {
|
|
42
|
+
throw new Error(`Invalid output from esbuild. Expected only one '${extension}' file but found ${matchedFiles.length}`);
|
|
43
|
+
}
|
|
44
|
+
const output = Buffer.from(matchedFiles[0].contents).toString('utf-8');
|
|
45
|
+
return output;
|
|
46
|
+
};
|
|
47
|
+
const compileBundle = async ({ entryPoint, metaFile, sourceMap, initialProperties, includeCss, }) => {
|
|
48
|
+
const res = await (0, esbuild_1.build)({
|
|
49
|
+
...sharedConfig(includeCss),
|
|
50
|
+
entryPoints: [entryPoint],
|
|
51
|
+
metafile: metaFile,
|
|
52
|
+
sourcemap: sourceMap ? 'inline' : undefined,
|
|
53
|
+
...getEsBuildConfig(entryPoint),
|
|
54
|
+
write: false,
|
|
55
|
+
});
|
|
56
|
+
const output = getOutput('.js', res);
|
|
57
|
+
let result = {
|
|
58
|
+
bundle: '',
|
|
59
|
+
};
|
|
60
|
+
if (!sourceMap) {
|
|
61
|
+
result.bundle = output;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
result.bundle = removeSourceMap(output);
|
|
65
|
+
}
|
|
66
|
+
if (initialProperties) {
|
|
67
|
+
result.bundle = `window.initialProperties = ${JSON.stringify(initialProperties)};${result.bundle}`;
|
|
68
|
+
}
|
|
69
|
+
if (metaFile) {
|
|
70
|
+
result = {
|
|
71
|
+
...result,
|
|
72
|
+
metaFile: JSON.stringify(res.metafile),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (sourceMap) {
|
|
76
|
+
result = {
|
|
77
|
+
...result,
|
|
78
|
+
sourceMap: extractSourceMap(output),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
};
|
|
83
|
+
exports.compileBundle = compileBundle;
|
|
84
|
+
const bundleResponse = async ({ entryPoint, initialProperties, }) => {
|
|
85
|
+
const res = await (0, exports.compileBundle)({
|
|
86
|
+
entryPoint,
|
|
87
|
+
initialProperties,
|
|
88
|
+
includeCss: true,
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
statusCode: 201,
|
|
92
|
+
headers: {
|
|
93
|
+
'Content-Type': 'application/javascript',
|
|
94
|
+
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
95
|
+
Pragma: 'no-cache',
|
|
96
|
+
Expire: '0',
|
|
97
|
+
SourceMap: '?resource=sourcemap',
|
|
98
|
+
},
|
|
99
|
+
body: res.bundle,
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
exports.bundleResponse = bundleResponse;
|
|
103
|
+
const extractSourceMap = (output) => {
|
|
104
|
+
const marker = '//# sourceMappingURL=data:application/json;base64,';
|
|
105
|
+
const startContent = output.indexOf(marker) + marker.length;
|
|
106
|
+
const sourceMapBase64Data = output.substring(startContent);
|
|
107
|
+
const sourceMapData = Buffer.from(sourceMapBase64Data, 'base64').toString('utf-8');
|
|
108
|
+
return sourceMapData;
|
|
109
|
+
};
|
|
110
|
+
const removeSourceMap = (output) => {
|
|
111
|
+
const marker = '//# sourceMappingURL=data:application/json;base64,';
|
|
112
|
+
const startContent = output.indexOf(marker);
|
|
113
|
+
const withoutSourceMap = output.substring(0, startContent);
|
|
114
|
+
return withoutSourceMap;
|
|
115
|
+
};
|
|
116
|
+
const sourceMapResponse = async ({ entryPoint, }) => {
|
|
117
|
+
const res = await (0, esbuild_1.build)({
|
|
118
|
+
...sharedConfig(false),
|
|
119
|
+
entryPoints: [entryPoint],
|
|
120
|
+
sourcemap: 'inline',
|
|
121
|
+
...getEsBuildConfig(entryPoint),
|
|
122
|
+
write: false,
|
|
123
|
+
});
|
|
124
|
+
const output = Buffer.from(res.outputFiles[0].contents).toString('utf-8');
|
|
125
|
+
const sourceMapData = extractSourceMap(output);
|
|
126
|
+
return {
|
|
127
|
+
statusCode: 201,
|
|
128
|
+
headers: {
|
|
129
|
+
'Content-Type': 'application/json',
|
|
130
|
+
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
131
|
+
Pragma: 'no-cache',
|
|
132
|
+
Expire: '0',
|
|
133
|
+
},
|
|
134
|
+
body: sourceMapData,
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
exports.sourceMapResponse = sourceMapResponse;
|
|
138
|
+
//# sourceMappingURL=compileBundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compileBundle.js","sourceRoot":"","sources":["../../src/compileBundle.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAuE;AACvE,oEAAwD;AAExD,0GAA0D;AAG1D,kDAAkE;AAClE,+BAA+B;AAE/B,MAAM,YAAY,GAAG,CAAC,UAAmB,EAAgB,EAAE;IACzD,OAAO;QACL,OAAO,EAAE;YACP,IAAA,2CAAS,EAAC;gBACR,gBAAgB,EAAE,CAAC,UAAU;aAC9B,CAAC;YACF,IAAA,8BAAS,GAAE;SACZ;QACD,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,qBAAqB;QAC9B,QAAQ,EAAE;YACR,SAAS;YACT,6BAA6B;YAC7B,gCAAgC,EAAE,2CAA2C;SAC9E;QACD,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,SAAS;QACnB,MAAM,EAAE,MAAM;QACd,WAAW,EAAE,IAAI;KAClB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,UAAkB,EAAgB,EAAE;IAC5D,MAAM,aAAa,GAAG,IAAA,qBAAU,EAAe,uBAAuB,CAAC,CAAC;IACxE,MAAM,gBAAgB,GAAG,IAAA,0BAAe,EACtC,IAA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ACZ;QACD,IAAI,EAAE,aAAa;KACpB,CAAC;AACJ,CAAC,CAAC;AA1BW,QAAA,iBAAiB,qBA0B5B"}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda';
|
|
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';
|
|
6
|
-
export declare const clientBundleFileName = "client.bundle.js";
|
|
7
|
-
export declare const clientCSSFileName = "client.bundle.css";
|
|
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;
|
|
24
|
-
}
|
|
25
|
-
export interface RenderPageProps<PropType> {
|
|
26
|
-
entryPoint: string;
|
|
27
|
-
event: APIGatewayProxyEventV2;
|
|
28
|
-
renderDocument: (props: RenderDocumentProps<PropType>) => string;
|
|
29
|
-
component: React.FunctionComponent<PropType>;
|
|
30
|
-
staticFileMapper?: StaticFileMapper;
|
|
31
|
-
staticFileMapperStore?: unknown;
|
|
32
|
-
properties: PropType;
|
|
33
|
-
buildConfig: () => BuildConfiguration;
|
|
34
|
-
}
|
|
35
|
-
export declare const renderPage: <PropType>({ entryPoint, event, renderDocument, staticFileMapper, staticFileMapperStore, component, properties, buildConfig, }: RenderPageProps<PropType>) => Promise<APIGatewayProxyResultV2>;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda';
|
|
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';
|
|
6
|
+
export declare const clientBundleFileName = "client.bundle.js";
|
|
7
|
+
export declare const clientCSSFileName = "client.bundle.css";
|
|
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;
|
|
24
|
+
}
|
|
25
|
+
export interface RenderPageProps<PropType> {
|
|
26
|
+
entryPoint: string;
|
|
27
|
+
event: APIGatewayProxyEventV2;
|
|
28
|
+
renderDocument: (props: RenderDocumentProps<PropType>) => string;
|
|
29
|
+
component: React.FunctionComponent<PropType>;
|
|
30
|
+
staticFileMapper?: StaticFileMapper;
|
|
31
|
+
staticFileMapperStore?: unknown;
|
|
32
|
+
properties: PropType;
|
|
33
|
+
buildConfig: () => BuildConfiguration;
|
|
34
|
+
}
|
|
35
|
+
export declare const renderPage: <PropType>({ entryPoint, event, renderDocument, staticFileMapper, staticFileMapperStore, component, properties, buildConfig, }: RenderPageProps<PropType>) => Promise<APIGatewayProxyResultV2>;
|
|
36
36
|
//# sourceMappingURL=templateSSRServer.d.ts.map
|
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.renderPage = exports.clientCSSFileName = exports.clientBundleFileName = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const lambda_compression_1 = require("lambda-compression");
|
|
9
|
-
const server_1 = require("react-dom/server");
|
|
10
|
-
const utils_esbuild_1 = require("@goldstack/utils-esbuild");
|
|
11
|
-
const fs_1 = require("fs");
|
|
12
|
-
const static_file_mapper_1 = require("static-file-mapper");
|
|
13
|
-
exports.clientBundleFileName = 'client.bundle.js';
|
|
14
|
-
exports.clientCSSFileName = 'client.bundle.css';
|
|
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
|
-
}
|
|
25
|
-
if (event.queryStringParameters && event.queryStringParameters['resource']) {
|
|
26
|
-
if (event.queryStringParameters['resource'].indexOf('js') > -1) {
|
|
27
|
-
if (process.env.AWS_LAMBDA_FUNCTION_NAME) {
|
|
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
|
-
}
|
|
37
|
-
return (0, lambda_compression_1.compress)(event, {
|
|
38
|
-
statusCode: 200,
|
|
39
|
-
headers: {
|
|
40
|
-
'Content-Type': 'application/javascript',
|
|
41
|
-
SourceMap,
|
|
42
|
-
},
|
|
43
|
-
body: `${(0, fs_1.readFileSync)(exports.clientBundleFileName, 'utf-8')}`,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
// if not running in Lambda build bundle dynamically
|
|
48
|
-
return (0, lambda_compression_1.compress)(event,
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
50
|
-
require((0, utils_esbuild_1.excludeInBundle)('@goldstack/template-ssr-server-compile-bundle')).bundleResponse({
|
|
51
|
-
entryPoint,
|
|
52
|
-
buildConfig: buildConfig(),
|
|
53
|
-
}));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (event.queryStringParameters['resource'].indexOf('sourcemap') > -1) {
|
|
57
|
-
if (process.env.AWS_LAMBDA_FUNCTION_NAME) {
|
|
58
|
-
throw new Error('sourcemap resource not supported in Lambda. Please load sourcemap from static files.');
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
return (0, lambda_compression_1.compress)(event,
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
63
|
-
require((0, utils_esbuild_1.excludeInBundle)('@goldstack/template-ssr-server-compile-bundle')).sourceMapResponse({
|
|
64
|
-
entryPoint,
|
|
65
|
-
buildConfig: buildConfig(),
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const page = (0, server_1.renderToString)(react_1.default.createElement(component, properties));
|
|
71
|
-
let styles;
|
|
72
|
-
// only inject styles when in lambda - otherwise they are loaded dynamically
|
|
73
|
-
if (process.env.AWS_LAMBDA_FUNCTION_NAME) {
|
|
74
|
-
styles = (0, fs_1.readFileSync)(exports.clientCSSFileName, 'utf-8');
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
styles = undefined;
|
|
78
|
-
}
|
|
79
|
-
const document = renderDocument({
|
|
80
|
-
injectIntoHead: `${styles ? `<style>${styles}</style>` : ''}`,
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.renderPage = exports.clientCSSFileName = exports.clientBundleFileName = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const lambda_compression_1 = require("lambda-compression");
|
|
9
|
+
const server_1 = require("react-dom/server");
|
|
10
|
+
const utils_esbuild_1 = require("@goldstack/utils-esbuild");
|
|
11
|
+
const fs_1 = require("fs");
|
|
12
|
+
const static_file_mapper_1 = require("static-file-mapper");
|
|
13
|
+
exports.clientBundleFileName = 'client.bundle.js';
|
|
14
|
+
exports.clientCSSFileName = 'client.bundle.css';
|
|
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
|
+
}
|
|
25
|
+
if (event.queryStringParameters && event.queryStringParameters['resource']) {
|
|
26
|
+
if (event.queryStringParameters['resource'].indexOf('js') > -1) {
|
|
27
|
+
if (process.env.AWS_LAMBDA_FUNCTION_NAME) {
|
|
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
|
+
}
|
|
37
|
+
return (0, lambda_compression_1.compress)(event, {
|
|
38
|
+
statusCode: 200,
|
|
39
|
+
headers: {
|
|
40
|
+
'Content-Type': 'application/javascript',
|
|
41
|
+
SourceMap,
|
|
42
|
+
},
|
|
43
|
+
body: `${(0, fs_1.readFileSync)(exports.clientBundleFileName, 'utf-8')}`,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// if not running in Lambda build bundle dynamically
|
|
48
|
+
return (0, lambda_compression_1.compress)(event,
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
50
|
+
require((0, utils_esbuild_1.excludeInBundle)('@goldstack/template-ssr-server-compile-bundle')).bundleResponse({
|
|
51
|
+
entryPoint,
|
|
52
|
+
buildConfig: buildConfig(),
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (event.queryStringParameters['resource'].indexOf('sourcemap') > -1) {
|
|
57
|
+
if (process.env.AWS_LAMBDA_FUNCTION_NAME) {
|
|
58
|
+
throw new Error('sourcemap resource not supported in Lambda. Please load sourcemap from static files.');
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return (0, lambda_compression_1.compress)(event,
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
63
|
+
require((0, utils_esbuild_1.excludeInBundle)('@goldstack/template-ssr-server-compile-bundle')).sourceMapResponse({
|
|
64
|
+
entryPoint,
|
|
65
|
+
buildConfig: buildConfig(),
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const page = (0, server_1.renderToString)(react_1.default.createElement(component, properties));
|
|
71
|
+
let styles;
|
|
72
|
+
// only inject styles when in lambda - otherwise they are loaded dynamically
|
|
73
|
+
if (process.env.AWS_LAMBDA_FUNCTION_NAME) {
|
|
74
|
+
styles = (0, fs_1.readFileSync)(exports.clientCSSFileName, 'utf-8');
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
styles = undefined;
|
|
78
|
+
}
|
|
79
|
+
const document = renderDocument({
|
|
80
|
+
injectIntoHead: `${styles ? `<style>${styles}</style>` : ''}`,
|
|
81
81
|
injectIntoBody: `
|
|
82
82
|
<div id="root">${page}</div>
|
|
83
83
|
<script>window.initialProperties=${JSON.stringify(properties)};</script>
|
|
84
84
|
<script src="?resource=js"></script>
|
|
85
|
-
`,
|
|
86
|
-
staticFileMapper: staticFileMapper,
|
|
87
|
-
event,
|
|
88
|
-
properties,
|
|
89
|
-
});
|
|
90
|
-
return (0, lambda_compression_1.compress)(event, {
|
|
91
|
-
statusCode: 200,
|
|
92
|
-
headers: {
|
|
93
|
-
'Content-Type': 'text/html',
|
|
94
|
-
},
|
|
95
|
-
body: document,
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
exports.renderPage = renderPage;
|
|
85
|
+
`,
|
|
86
|
+
staticFileMapper: staticFileMapper,
|
|
87
|
+
event,
|
|
88
|
+
properties,
|
|
89
|
+
});
|
|
90
|
+
return (0, lambda_compression_1.compress)(event, {
|
|
91
|
+
statusCode: 200,
|
|
92
|
+
headers: {
|
|
93
|
+
'Content-Type': 'text/html',
|
|
94
|
+
},
|
|
95
|
+
body: document,
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
exports.renderPage = renderPage;
|
|
99
99
|
//# sourceMappingURL=templateSSRServer.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goldstack/template-ssr-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Building blocks for implementing server-side rendered pages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"goldstack",
|
|
@@ -38,26 +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.
|
|
44
|
-
"@goldstack/utils-aws-lambda": "0.
|
|
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.
|
|
41
|
+
"@goldstack/infra": "0.4.0",
|
|
42
|
+
"@goldstack/infra-aws": "0.4.0",
|
|
43
|
+
"@goldstack/template-ssr-server-compile-bundle": "0.3.0",
|
|
44
|
+
"@goldstack/utils-aws-lambda": "0.3.0",
|
|
45
|
+
"@goldstack/utils-esbuild": "0.5.0",
|
|
46
|
+
"@goldstack/utils-package": "0.4.0",
|
|
47
|
+
"@goldstack/utils-package-config-embedded": "0.5.0",
|
|
48
|
+
"@goldstack/utils-sh": "0.5.0",
|
|
49
|
+
"@goldstack/utils-template": "0.4.0",
|
|
50
|
+
"@goldstack/utils-terraform": "0.4.0",
|
|
51
|
+
"lambda-compression": "0.2.0",
|
|
52
52
|
"react": "^18.2.0",
|
|
53
53
|
"react-dom": "^18.2.0",
|
|
54
54
|
"source-map-support": "^0.5.21",
|
|
55
|
-
"static-file-mapper": "0.
|
|
55
|
+
"static-file-mapper": "0.3.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@goldstack/utils-docs-cli": "0.3.11",
|
|
59
|
-
"@goldstack/utils-git": "0.
|
|
60
|
-
"@goldstack/utils-package-config-generate": "0.
|
|
59
|
+
"@goldstack/utils-git": "0.2.0",
|
|
60
|
+
"@goldstack/utils-package-config-generate": "0.3.0",
|
|
61
61
|
"@types/aws-lambda": "^8.10.88",
|
|
62
62
|
"@types/jest": "^28.1.8",
|
|
63
63
|
"@types/node": "^18.7.13",
|