@hubspot/cms-dev-server 0.4.18 → 0.6.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.
- package/dist/components/ModulesList.js +14 -0
- package/dist/components/PartialsList.js +13 -0
- package/dist/createDevServer.js +162 -0
- package/dist/createViteDevServer.js +51 -0
- package/dist/fsevents-72LCIACT.node +0 -0
- package/dist/index.js +3 -2
- package/dist/internalSsr.js +20 -12
- package/dist/lib/cli.js +27 -0
- package/dist/lib/debug.js +2 -0
- package/dist/lib/errors.js +22 -0
- package/dist/lib/fullOriginalUrlFromRequest.js +3 -0
- package/dist/lib/httpsRedirectingServer.js +48 -0
- package/dist/lib/moduleGraph.js +11 -0
- package/dist/lib/proxyHelpers.js +70 -0
- package/dist/lib/proxyHelpers.test.js +136 -0
- package/dist/lib/renderComponentWithCSS.js +26 -0
- package/dist/lib/renderHelpers.js +45 -0
- package/dist/lib/renderModule.js +56 -0
- package/dist/lib/renderPartial.js +15 -0
- package/dist/lib/templates.js +55 -0
- package/dist/proxyPage/constants.js +1 -0
- package/dist/proxyPage/fetchContentMetadata.js +59 -0
- package/dist/proxyPage/fetchDomains.js +29 -0
- package/dist/proxyPage/fetchPreviewInfo.js +37 -0
- package/dist/proxyPage/proxyPage.js +174 -0
- package/dist/proxyPage/renderLocalError.js +27 -0
- package/dist/proxyPage/utils.js +38 -0
- package/dist/routes/createDevServerRoutes.js +43 -0
- package/dist/routes/homeRouteHandler.js +12 -0
- package/dist/routes/linksToAllModulesRouteHandler.js +10 -0
- package/dist/routes/linksToAllPartialsRouteHandler.js +10 -0
- package/dist/routes/module.js +41 -0
- package/dist/routes/partial.js +30 -0
- package/dist/routes/proxyPageResourceRedirect.js +22 -0
- package/dist/routes/proxyPageRouteHandler.js +40 -0
- package/dist/routes/proxyPathPageResourceRedirect.js +36 -0
- package/dist/routes/proxyPathPageRouteHandler.js +43 -0
- package/dist/run.js +119 -56
- package/dist/shadowDevServer/createShadowDevServerRoutes.js +63 -0
- package/dist/shadowDevServer/startShadowDevServer.js +31 -0
- package/dist/storybook/getFieldsArgTypes.js +54 -0
- package/dist/storybook/getFieldsArgTypes.test.js +91 -0
- package/dist/storybook/getNestedFieldObjectForArgs.js +22 -0
- package/dist/storybook/getNestedFieldObjectForArgs.test.js +40 -0
- package/dist/storybook/index.js +1 -1
- package/dist/storybook/main.js +20 -12
- package/dist/storybook/moduleStory.js +61 -0
- package/dist/storybook/preview.js +9 -0
- package/dist/storybook/types.js +1 -0
- package/package.json +5 -5
package/dist/run.js
CHANGED
|
@@ -60,7 +60,7 @@ import { createRequire } from "module";
|
|
|
60
60
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
61
61
|
import stream from "stream";
|
|
62
62
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
63
|
-
import {
|
|
63
|
+
import { createServerRenderContextV2, ServerRenderContext } from "@hubspot/cms-components";
|
|
64
64
|
import { createHash } from "crypto";
|
|
65
65
|
import { existsSync, readdirSync, lstatSync } from "fs";
|
|
66
66
|
import { join } from "path/posix";
|
|
@@ -196,7 +196,7 @@ function resolveIslandPlugin(gates) {
|
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
198
|
}
|
|
199
|
-
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport {
|
|
199
|
+
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport {\n ClientRenderContextProvider,\n buildIslandIdentifierPrefix,\n} from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
200
200
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
201
201
|
function clientIslandEntryPlugin() {
|
|
202
202
|
return {
|
|
@@ -248,21 +248,21 @@ var promiseForNewWritableStream = () => {
|
|
|
248
248
|
});
|
|
249
249
|
return { streamDonePromise, writableStream };
|
|
250
250
|
};
|
|
251
|
-
var renderStreamToPromise = async (reactElements,
|
|
251
|
+
var renderStreamToPromise = async (reactElements, options) => {
|
|
252
252
|
const { streamDonePromise, writableStream } = promiseForNewWritableStream();
|
|
253
253
|
const {
|
|
254
254
|
pipe
|
|
255
255
|
/* abort */
|
|
256
256
|
} = renderToPipeableStream(reactElements, {
|
|
257
|
-
...
|
|
257
|
+
...options || {},
|
|
258
258
|
onShellReady() {
|
|
259
259
|
},
|
|
260
260
|
onAllReady() {
|
|
261
261
|
pipe(writableStream);
|
|
262
|
+
if (options == null ? void 0 : options.onAllReady) {
|
|
263
|
+
options.onAllReady();
|
|
264
|
+
}
|
|
262
265
|
}
|
|
263
|
-
// We will log the error sent to the writable, any need to do something in these callbacks?
|
|
264
|
-
// onShellError(error) {},
|
|
265
|
-
// onError(error) {},
|
|
266
266
|
});
|
|
267
267
|
return streamDonePromise;
|
|
268
268
|
};
|
|
@@ -289,8 +289,11 @@ ${consoleLines.join("\n")}
|
|
|
289
289
|
${groupEnd}</script>
|
|
290
290
|
`;
|
|
291
291
|
};
|
|
292
|
-
async function renderOnServer(elements, pageUrl, environmentConfig, debugName, renderOptions) {
|
|
293
|
-
const renderContext =
|
|
292
|
+
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, debugName, renderOptions) {
|
|
293
|
+
const renderContext = createServerRenderContextV2(pageUrl, {
|
|
294
|
+
environmentConfig,
|
|
295
|
+
entryPointBasePath
|
|
296
|
+
});
|
|
294
297
|
let html = await renderStreamToPromise(
|
|
295
298
|
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
|
296
299
|
renderOptions
|
|
@@ -389,13 +392,16 @@ function findAllPartialsInRoot(webRoot2) {
|
|
|
389
392
|
);
|
|
390
393
|
return { partialNames, partialSubpaths };
|
|
391
394
|
}
|
|
392
|
-
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl) {
|
|
395
|
+
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath) {
|
|
393
396
|
const globals = [
|
|
394
397
|
`window.__hsEnvConfig = ${JSON.stringify(environmentConfig.toJSON())};`
|
|
395
398
|
];
|
|
396
399
|
if (hsServerPageUrl) {
|
|
397
400
|
globals.push(`window.__hsServerPageUrl = '${hsServerPageUrl}';`);
|
|
398
401
|
}
|
|
402
|
+
if (hsBasePath) {
|
|
403
|
+
globals.push(`window.__hsBasePath = '${hsBasePath}';`);
|
|
404
|
+
}
|
|
399
405
|
return `
|
|
400
406
|
<script type="text/javascript">
|
|
401
407
|
${globals.join("\n ")}
|
|
@@ -435,16 +441,6 @@ function renderFieldsToJson(fields) {
|
|
|
435
441
|
return moduleJson;
|
|
436
442
|
}
|
|
437
443
|
|
|
438
|
-
// src/lib/moduleGraph.ts
|
|
439
|
-
var findFullPathInModuleGraph = (modulePathNoExtension, moduleGraph) => {
|
|
440
|
-
for (const extension of COMPONENT_EXTENSIONS) {
|
|
441
|
-
const pathToTry = `${modulePathNoExtension}${extension}`;
|
|
442
|
-
if (moduleGraph.fileToModulesMap.has(pathToTry)) {
|
|
443
|
-
return pathToTry;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
|
|
448
444
|
// src/lib/packagePath.ts
|
|
449
445
|
import path2 from "path";
|
|
450
446
|
import url from "url";
|
|
@@ -462,10 +458,18 @@ function packagePath(metaUrl, projectPath) {
|
|
|
462
458
|
);
|
|
463
459
|
}
|
|
464
460
|
|
|
465
|
-
// src/lib/
|
|
466
|
-
|
|
467
|
-
const
|
|
468
|
-
|
|
461
|
+
// src/lib/moduleGraph.ts
|
|
462
|
+
var findFullPathInModuleGraph = (modulePathNoExtension, moduleGraph) => {
|
|
463
|
+
for (const extension of COMPONENT_EXTENSIONS) {
|
|
464
|
+
const pathToTry = `${modulePathNoExtension}${extension}`;
|
|
465
|
+
if (moduleGraph.fileToModulesMap.has(pathToTry)) {
|
|
466
|
+
return pathToTry;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
// src/lib/pathHelpers.ts
|
|
472
|
+
var getComponentPaths = (viteServer, componentPath) => {
|
|
469
473
|
let componentPathWithExtension;
|
|
470
474
|
let componentPathNoExtension;
|
|
471
475
|
if (hasComponentExtension(componentPath)) {
|
|
@@ -474,13 +478,6 @@ async function renderComponentWithCSS(viteServer, componentPath, Component, prop
|
|
|
474
478
|
} else {
|
|
475
479
|
componentPathNoExtension = componentPath;
|
|
476
480
|
}
|
|
477
|
-
const { html, renderContext } = await renderComponentOnServer(
|
|
478
|
-
Component,
|
|
479
|
-
props,
|
|
480
|
-
pageUrl,
|
|
481
|
-
environmentConfig,
|
|
482
|
-
renderOptions
|
|
483
|
-
);
|
|
484
481
|
if (!componentPathWithExtension) {
|
|
485
482
|
componentPathWithExtension = findFullPathInModuleGraph(
|
|
486
483
|
componentPathNoExtension,
|
|
@@ -492,6 +489,34 @@ async function renderComponentWithCSS(viteServer, componentPath, Component, prop
|
|
|
492
489
|
);
|
|
493
490
|
}
|
|
494
491
|
}
|
|
492
|
+
return [componentPathNoExtension, componentPathWithExtension];
|
|
493
|
+
};
|
|
494
|
+
var getEntryPointBasePath = (componentPath) => {
|
|
495
|
+
if (componentPath.includes(ENTRY_POINTS_PATH)) {
|
|
496
|
+
return `partial/${componentPath.split(ENTRY_POINTS_PATH)[1]}`;
|
|
497
|
+
}
|
|
498
|
+
if (componentPath.includes(MODULE_FOLDER_PATH)) {
|
|
499
|
+
return `module/${componentPath.split(MODULE_FOLDER_PATH)[1]}`;
|
|
500
|
+
}
|
|
501
|
+
throw new Error("Unknown entry point path type");
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
// src/lib/renderComponentWithCSS.ts
|
|
505
|
+
async function renderComponentWithCSS(viteServer, componentPath, Component, props, pageUrl, entryPointBasePath, environmentConfig, renderOptions) {
|
|
506
|
+
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
507
|
+
const { renderComponentOnServer, collectCssInDev } = await viteServer.ssrLoadModule(internalSsrPath);
|
|
508
|
+
const [, componentPathWithExtension] = getComponentPaths(
|
|
509
|
+
viteServer,
|
|
510
|
+
componentPath
|
|
511
|
+
);
|
|
512
|
+
const { html, renderContext } = await renderComponentOnServer(
|
|
513
|
+
Component,
|
|
514
|
+
props,
|
|
515
|
+
pageUrl,
|
|
516
|
+
environmentConfig,
|
|
517
|
+
entryPointBasePath,
|
|
518
|
+
renderOptions
|
|
519
|
+
);
|
|
495
520
|
const cssNeeded = collectCssInDev(componentPathWithExtension, viteServer);
|
|
496
521
|
return { html, cssNeeded, renderContext };
|
|
497
522
|
}
|
|
@@ -539,7 +564,7 @@ var logPartialInfo = (partialPath, props) => {
|
|
|
539
564
|
};
|
|
540
565
|
|
|
541
566
|
// src/lib/renderPartial.ts
|
|
542
|
-
async function renderPartial(viteServer, partialPath, props, pageUrl, environmentConfig, renderOptions) {
|
|
567
|
+
async function renderPartial(viteServer, partialPath, props, pageUrl, basePath, environmentConfig, renderOptions) {
|
|
543
568
|
logPartialInfo(partialPath, props);
|
|
544
569
|
let serverSideProps;
|
|
545
570
|
const componentModule = await viteServer.ssrLoadModule(partialPath);
|
|
@@ -571,6 +596,7 @@ async function renderPartial(viteServer, partialPath, props, pageUrl, environmen
|
|
|
571
596
|
Component,
|
|
572
597
|
{ ...props, ...serverSideProps },
|
|
573
598
|
pageUrl,
|
|
599
|
+
basePath,
|
|
574
600
|
environmentConfig,
|
|
575
601
|
renderOptions
|
|
576
602
|
);
|
|
@@ -632,7 +658,8 @@ var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, tit
|
|
|
632
658
|
if (renderContext.islands.length) {
|
|
633
659
|
const globalScriptBlock = getServerGlobalsToInject(
|
|
634
660
|
renderContext.environmentConfig,
|
|
635
|
-
renderContext.pageUrl
|
|
661
|
+
renderContext.pageUrl,
|
|
662
|
+
renderContext.entryPointBasePath
|
|
636
663
|
);
|
|
637
664
|
htmlTemplate = await createIslandHtmlTemplate(
|
|
638
665
|
baseTemplatePath,
|
|
@@ -682,7 +709,7 @@ var getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, perServerReque
|
|
|
682
709
|
};
|
|
683
710
|
|
|
684
711
|
// src/routes/partial.ts
|
|
685
|
-
import { buildStaticEnvConfig } from "@hubspot/cms-components
|
|
712
|
+
import { buildStaticEnvConfig } from "@hubspot/cms-components";
|
|
686
713
|
var partialRouteHandler = async (request2, response) => {
|
|
687
714
|
const {
|
|
688
715
|
authedPortalId,
|
|
@@ -711,6 +738,7 @@ var partialRouteHandler = async (request2, response) => {
|
|
|
711
738
|
partialName
|
|
712
739
|
].join("/")
|
|
713
740
|
);
|
|
741
|
+
const basePath = getEntryPointBasePath(partialPath);
|
|
714
742
|
const environmentConfig = buildStaticEnvConfig(
|
|
715
743
|
authedPortalId,
|
|
716
744
|
authedHublet,
|
|
@@ -728,6 +756,7 @@ var partialRouteHandler = async (request2, response) => {
|
|
|
728
756
|
partialPath,
|
|
729
757
|
{},
|
|
730
758
|
fullOriginalUrlFromRequest(request2),
|
|
759
|
+
basePath,
|
|
731
760
|
environmentConfig,
|
|
732
761
|
{
|
|
733
762
|
identifierPrefix: getEntryPointHash(entrypointPath)
|
|
@@ -782,7 +811,8 @@ var linksToAllPartialRouteHandler = async (request2, response) => {
|
|
|
782
811
|
const { html: responseHtml } = await renderOnServer(
|
|
783
812
|
/* @__PURE__ */ jsx4(PartialsList, { webRoot: webRoot2, partialNames }),
|
|
784
813
|
null,
|
|
785
|
-
null
|
|
814
|
+
null,
|
|
815
|
+
""
|
|
786
816
|
);
|
|
787
817
|
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
788
818
|
};
|
|
@@ -818,14 +848,15 @@ var linksToAllModuleRouteHandler = async (request2, response) => {
|
|
|
818
848
|
const { html: responseHtml } = await renderOnServer(
|
|
819
849
|
/* @__PURE__ */ jsx6(ModulesList_default, { webRoot: webRoot2, moduleNames }),
|
|
820
850
|
null,
|
|
821
|
-
null
|
|
851
|
+
null,
|
|
852
|
+
""
|
|
822
853
|
);
|
|
823
854
|
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
824
855
|
};
|
|
825
856
|
var linksToAllModulesRouteHandler_default = linksToAllModuleRouteHandler;
|
|
826
857
|
|
|
827
858
|
// src/routes/module.ts
|
|
828
|
-
import { buildStaticEnvConfig as buildStaticEnvConfig2 } from "@hubspot/cms-components
|
|
859
|
+
import { buildStaticEnvConfig as buildStaticEnvConfig2 } from "@hubspot/cms-components";
|
|
829
860
|
import path4 from "path";
|
|
830
861
|
import { normalizePath as normalizePath3 } from "vite";
|
|
831
862
|
|
|
@@ -844,7 +875,7 @@ var lookForModuleInFolder = async (modulePath, viteServer) => {
|
|
|
844
875
|
}
|
|
845
876
|
return [componentModule, insideFolderPath];
|
|
846
877
|
};
|
|
847
|
-
async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}, pageUrl, environmentConfig, renderOptions) {
|
|
878
|
+
async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}, pageUrl, basePath, environmentConfig, renderOptions) {
|
|
848
879
|
console.log("Rendering module", requestedModulePath);
|
|
849
880
|
const ungatedForServerSideProps = isUngatedFor(
|
|
850
881
|
environmentConfig.getGates(),
|
|
@@ -897,6 +928,7 @@ async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}
|
|
|
897
928
|
Component,
|
|
898
929
|
{ ...props, ...serverSideProps },
|
|
899
930
|
pageUrl,
|
|
931
|
+
basePath,
|
|
900
932
|
environmentConfig,
|
|
901
933
|
renderOptions
|
|
902
934
|
);
|
|
@@ -951,6 +983,7 @@ var moduleRouteHandler = async (request2, response) => {
|
|
|
951
983
|
);
|
|
952
984
|
}
|
|
953
985
|
}
|
|
986
|
+
const basePath = getEntryPointBasePath(modulePath);
|
|
954
987
|
const environmentConfig = buildStaticEnvConfig2(
|
|
955
988
|
authedPortalId,
|
|
956
989
|
authedHublet,
|
|
@@ -968,6 +1001,7 @@ var moduleRouteHandler = async (request2, response) => {
|
|
|
968
1001
|
modulePath,
|
|
969
1002
|
fieldOverrides,
|
|
970
1003
|
fullOriginalUrlFromRequest(request2),
|
|
1004
|
+
basePath,
|
|
971
1005
|
environmentConfig,
|
|
972
1006
|
{
|
|
973
1007
|
identifierPrefix: getEntryPointHash(entrypointPath)
|
|
@@ -1267,11 +1301,19 @@ ${error.error.message}`);
|
|
|
1267
1301
|
|
|
1268
1302
|
// src/proxyPage/proxyPage.ts
|
|
1269
1303
|
import {
|
|
1270
|
-
buildStaticEnvConfig as buildStaticEnvConfig3
|
|
1271
|
-
} from "@hubspot/cms-components/config";
|
|
1272
|
-
import {
|
|
1304
|
+
buildStaticEnvConfig as buildStaticEnvConfig3,
|
|
1273
1305
|
mergeServerRequestData_internal
|
|
1274
1306
|
} from "@hubspot/cms-components";
|
|
1307
|
+
var getEntryPointBasePathFromProxyRequest = (request2) => {
|
|
1308
|
+
if (!request2) {
|
|
1309
|
+
return "";
|
|
1310
|
+
}
|
|
1311
|
+
const { path: requestPath, pathParamDict } = request2;
|
|
1312
|
+
if (!pathParamDict || !pathParamDict.dynamic_slug) {
|
|
1313
|
+
return requestPath;
|
|
1314
|
+
}
|
|
1315
|
+
return requestPath.replace(pathParamDict.dynamic_slug, "");
|
|
1316
|
+
};
|
|
1275
1317
|
var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, projectName, jsRenderingGates) => {
|
|
1276
1318
|
const url3 = new URL(urlToProxy);
|
|
1277
1319
|
console.log(`Proxying request to ${url3.href}`, {
|
|
@@ -1313,7 +1355,7 @@ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, pro
|
|
|
1313
1355
|
}
|
|
1314
1356
|
});
|
|
1315
1357
|
};
|
|
1316
|
-
var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder, webRoot2, viteServer, pageUrl, environmentConfig, hsProjectJsonProjectName, webRootProjectComponent) => {
|
|
1358
|
+
var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder, webRoot2, viteServer, pageUrl, basePath, environmentConfig, hsProjectJsonProjectName, webRootProjectComponent) => {
|
|
1317
1359
|
const proxySchemaVersion = isUngatedFor(
|
|
1318
1360
|
environmentConfig.getGates(),
|
|
1319
1361
|
"CMS:JSRenderer:LocalProxySchemaVersion1"
|
|
@@ -1354,6 +1396,7 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
|
|
|
1354
1396
|
resolvedPath,
|
|
1355
1397
|
localRenderPlaceholderProps,
|
|
1356
1398
|
pageUrl,
|
|
1399
|
+
basePath,
|
|
1357
1400
|
environmentConfig,
|
|
1358
1401
|
{
|
|
1359
1402
|
identifierPrefix: getEntryPointHashWithIndexSuffix(
|
|
@@ -1368,6 +1411,7 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
|
|
|
1368
1411
|
resolvedPath,
|
|
1369
1412
|
localRenderPlaceholderProps,
|
|
1370
1413
|
pageUrl,
|
|
1414
|
+
basePath,
|
|
1371
1415
|
environmentConfig,
|
|
1372
1416
|
{
|
|
1373
1417
|
identifierPrefix: getEntryPointHashWithIndexSuffix(
|
|
@@ -1427,6 +1471,7 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
|
|
|
1427
1471
|
let numJsRenderFailures = 0;
|
|
1428
1472
|
let islands = [];
|
|
1429
1473
|
let mergedPerRequestState = /* @__PURE__ */ new Map();
|
|
1474
|
+
let basePath;
|
|
1430
1475
|
const renderPromisesByChunkIndex = new Array(
|
|
1431
1476
|
numPlaceholders
|
|
1432
1477
|
);
|
|
@@ -1439,12 +1484,21 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
|
|
|
1439
1484
|
offsetSoFar,
|
|
1440
1485
|
localRenderPlaceholder.startOffset
|
|
1441
1486
|
);
|
|
1487
|
+
if (basePath === void 0 && isUngatedFor(
|
|
1488
|
+
environmentConfig.getGates(),
|
|
1489
|
+
"CMS:JSRenderer:LocalProxySchemaVersion1"
|
|
1490
|
+
)) {
|
|
1491
|
+
basePath = getEntryPointBasePathFromProxyRequest(
|
|
1492
|
+
localRenderPlaceholder.json.request
|
|
1493
|
+
);
|
|
1494
|
+
}
|
|
1442
1495
|
const renderPromise = renderComponentForPlaceholder(
|
|
1443
1496
|
indexForThisRender,
|
|
1444
1497
|
localRenderPlaceholder,
|
|
1445
1498
|
webRoot2,
|
|
1446
1499
|
viteServer,
|
|
1447
1500
|
fullOriginalUrl,
|
|
1501
|
+
basePath,
|
|
1448
1502
|
environmentConfig,
|
|
1449
1503
|
projectName,
|
|
1450
1504
|
projectComponentPath
|
|
@@ -1488,7 +1542,7 @@ ${html}`;
|
|
|
1488
1542
|
response.write(foobar);
|
|
1489
1543
|
}
|
|
1490
1544
|
response.write(
|
|
1491
|
-
getServerGlobalsToInject(environmentConfig, fullOriginalUrl)
|
|
1545
|
+
getServerGlobalsToInject(environmentConfig, fullOriginalUrl, basePath)
|
|
1492
1546
|
);
|
|
1493
1547
|
if (islands.length > 0) {
|
|
1494
1548
|
const sortedIslandRoots = sortIslandRootsByPriority(islands);
|
|
@@ -1603,7 +1657,8 @@ var homeRouteHandler = async (request2, response) => {
|
|
|
1603
1657
|
/* @__PURE__ */ jsx7(ModulesList_default, { webRoot: webRoot2, moduleNames })
|
|
1604
1658
|
] }),
|
|
1605
1659
|
null,
|
|
1606
|
-
null
|
|
1660
|
+
null,
|
|
1661
|
+
""
|
|
1607
1662
|
);
|
|
1608
1663
|
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
1609
1664
|
};
|
|
@@ -1645,7 +1700,8 @@ async function proxyPathPageRouteHandler(request2, response, next) {
|
|
|
1645
1700
|
] })
|
|
1646
1701
|
] }),
|
|
1647
1702
|
null,
|
|
1648
|
-
null
|
|
1703
|
+
null,
|
|
1704
|
+
""
|
|
1649
1705
|
);
|
|
1650
1706
|
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
1651
1707
|
return;
|
|
@@ -1746,8 +1802,10 @@ var createDevServerRoutes = async (viteServer, storybookPort) => {
|
|
|
1746
1802
|
devServerApp.get("/proxy", proxyPathPageRouteHandler);
|
|
1747
1803
|
devServerApp.get("/partials/", linksToAllPartialsRouteHandler_default);
|
|
1748
1804
|
devServerApp.get("/partial/:partial", partial_default);
|
|
1805
|
+
devServerApp.get("/partial/:partial/*", partial_default);
|
|
1749
1806
|
devServerApp.get("/modules/", linksToAllModulesRouteHandler_default);
|
|
1750
1807
|
devServerApp.get("/module/:moduleName", module_default);
|
|
1808
|
+
devServerApp.get("/module/:moduleName/*", module_default);
|
|
1751
1809
|
devServerApp.get("/", homeRouteHandler_default);
|
|
1752
1810
|
devServerApp.get("/*", proxyPathPageResourceRedirect);
|
|
1753
1811
|
devServerApp.get("/*", proxyPageResourceRedirect);
|
|
@@ -1907,6 +1965,7 @@ async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy =
|
|
|
1907
1965
|
noExternal: "@hubspot/cms-components"
|
|
1908
1966
|
},
|
|
1909
1967
|
resolve: {
|
|
1968
|
+
conditions: ["server"],
|
|
1910
1969
|
dedupe: ["react", "react-dom", "@hubspot/cms-components"]
|
|
1911
1970
|
},
|
|
1912
1971
|
optimizeDeps: {
|
|
@@ -2068,6 +2127,7 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
|
|
|
2068
2127
|
let authedPortalId = null;
|
|
2069
2128
|
let authedEnv = null;
|
|
2070
2129
|
let jsRenderingGates = [];
|
|
2130
|
+
let personalAccessKey = null;
|
|
2071
2131
|
if (hubspotCliConfigPathOption2 && hubspotCliAccountNameOption2) {
|
|
2072
2132
|
console.log(
|
|
2073
2133
|
`Loading HS auth (account = ${hubspotCliAccountNameOption2}) configuration at: ${hubspotCliConfigPathOption2}`
|
|
@@ -2085,12 +2145,26 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
|
|
|
2085
2145
|
if (validateConfig()) {
|
|
2086
2146
|
authedPortalId = getAccountId3(hubspotCliAccountNameOption2);
|
|
2087
2147
|
authedEnv = getEnv2(hubspotCliAccountNameOption2);
|
|
2148
|
+
personalAccessKey = getAccountConfig(authedPortalId) && getAccountConfig(authedPortalId).personalAccessKey;
|
|
2088
2149
|
if (!authedPortalId && hubspotCliAccountNameOption2) {
|
|
2089
2150
|
console.error(
|
|
2090
2151
|
`Couldn't find ${hubspotCliAccountNameOption2} in your hubspot.config.yaml`
|
|
2091
2152
|
);
|
|
2092
2153
|
process.exit(1);
|
|
2093
2154
|
}
|
|
2155
|
+
if (personalAccessKey) {
|
|
2156
|
+
try {
|
|
2157
|
+
jsRenderingGates = await getJsRenderingGates(
|
|
2158
|
+
authedPortalId,
|
|
2159
|
+
authedEnv,
|
|
2160
|
+
personalAccessKey
|
|
2161
|
+
);
|
|
2162
|
+
} catch (e) {
|
|
2163
|
+
console.warn(
|
|
2164
|
+
`Unable to get gating information. gated features will not be availalbe in the local dev server`
|
|
2165
|
+
);
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2094
2168
|
} else {
|
|
2095
2169
|
console.warn(
|
|
2096
2170
|
`Couldn't find an account to use, make sure there is hubspot.config.yaml in this folder (or a parent).
|
|
@@ -2099,17 +2173,6 @@ If needed you can refer to another config file with --config.
|
|
|
2099
2173
|
Local proxy functionality will not work without setting up authentication.`
|
|
2100
2174
|
);
|
|
2101
2175
|
}
|
|
2102
|
-
try {
|
|
2103
|
-
const { personalAccessKey } = getAccountConfig(authedPortalId);
|
|
2104
|
-
jsRenderingGates = await getJsRenderingGates(
|
|
2105
|
-
authedPortalId,
|
|
2106
|
-
authedEnv,
|
|
2107
|
-
personalAccessKey
|
|
2108
|
-
);
|
|
2109
|
-
} catch (e) {
|
|
2110
|
-
console.error(e);
|
|
2111
|
-
console.warn("Unable to fetch gating information");
|
|
2112
|
-
}
|
|
2113
2176
|
let domainsToProxy = [];
|
|
2114
2177
|
if (sslEnabledOption2 && authedPortalId) {
|
|
2115
2178
|
try {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/* hs-eslint ignored failing-rules */
|
|
2
|
+
/* eslint-disable require-await */
|
|
3
|
+
import { Router } from 'express';
|
|
4
|
+
import { getAccountId } from '@hubspot/cli-lib/lib/config.js';
|
|
5
|
+
import cors from 'cors';
|
|
6
|
+
import { findLocalRenderPlaceholders } from '../lib/proxyHelpers.js';
|
|
7
|
+
import { makeProxyPreviewRequest } from '../proxyPage/proxyPage.js';
|
|
8
|
+
import fetchPreviewInfo from '../proxyPage/fetchPreviewInfo.js';
|
|
9
|
+
function getShadowDevServerCheckHandler(devServerPort) {
|
|
10
|
+
return async function shadowDevServerCheckHandler(request, response) {
|
|
11
|
+
const { query } = request;
|
|
12
|
+
if (query) {
|
|
13
|
+
const { hostName, pathName, protocol, contentId, portalId: portalIdString, } = query;
|
|
14
|
+
const pageUrl = `${protocol}//${hostName}${pathName}`;
|
|
15
|
+
const portalId = parseInt(portalIdString, 10);
|
|
16
|
+
let accountId;
|
|
17
|
+
let hasJSBuildingBlocks = false;
|
|
18
|
+
let localProxyUrl;
|
|
19
|
+
try {
|
|
20
|
+
accountId = getAccountId(portalId);
|
|
21
|
+
if (accountId === null) {
|
|
22
|
+
throw new Error();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
response
|
|
27
|
+
.status(500)
|
|
28
|
+
.end(`Unable to find account for hubid = ${portalId}. Please check your hubspot.config.yaml`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const previewInfo = await fetchPreviewInfo(accountId, portalId, contentId);
|
|
33
|
+
const { previewKey } = previewInfo;
|
|
34
|
+
const pageHtml = await makeProxyPreviewRequest(accountId, pageUrl, previewKey, contentId);
|
|
35
|
+
const localRenderPlaceholders = findLocalRenderPlaceholders(pageHtml);
|
|
36
|
+
if (localRenderPlaceholders.length) {
|
|
37
|
+
hasJSBuildingBlocks = true;
|
|
38
|
+
localProxyUrl = `http://${hostName}.hslocal.net:${devServerPort}${pathName}`;
|
|
39
|
+
}
|
|
40
|
+
response
|
|
41
|
+
.status(200)
|
|
42
|
+
.set({ 'Content-Type': 'application/json' })
|
|
43
|
+
.json({ hasJSBuildingBlocks, localProxyUrl });
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
response
|
|
47
|
+
.status(500)
|
|
48
|
+
.end(`Failed proxy render of page id = ${contentId} hub id = ${portalId}\n\n${error.stack}`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
response
|
|
54
|
+
.status(500)
|
|
55
|
+
.end(`Missing pageUrl param, cannot check for proxied page without a pageUrl`);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export default async function createShadowDevServerRoutes(devServerPort) {
|
|
60
|
+
const shadowDevServerRoutes = Router();
|
|
61
|
+
shadowDevServerRoutes.get('/check-if-local-dev-server', cors(), getShadowDevServerCheckHandler(devServerPort));
|
|
62
|
+
return shadowDevServerRoutes;
|
|
63
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import net from 'net';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import createShadowDevServerRoutes from './createShadowDevServerRoutes.js';
|
|
4
|
+
const testNetServer = net.createServer();
|
|
5
|
+
export default async function startShadowDevServer(devServerPort, shadowPort) {
|
|
6
|
+
const portIsTaken = await new Promise((res, rej) => {
|
|
7
|
+
console.log(`Starting proxy link server on port ${shadowPort}`);
|
|
8
|
+
testNetServer.once('error', err => {
|
|
9
|
+
if (err['code'] === 'EADDRINUSE') {
|
|
10
|
+
console.error(`Port ${shadowPort} is in use. HubSpot is unable to automatically create proxy links in the Sprocket Menu`);
|
|
11
|
+
res(true);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
rej(err);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
testNetServer.once('listening', () => {
|
|
18
|
+
testNetServer.close();
|
|
19
|
+
});
|
|
20
|
+
testNetServer.once('close', () => {
|
|
21
|
+
res(false);
|
|
22
|
+
});
|
|
23
|
+
testNetServer.listen(shadowPort);
|
|
24
|
+
});
|
|
25
|
+
if (portIsTaken) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const shadowDevServer = express();
|
|
29
|
+
shadowDevServer.listen(shadowPort);
|
|
30
|
+
shadowDevServer.use('/', await createShadowDevServerRoutes(devServerPort));
|
|
31
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export default function getFieldsArgTypes(fieldsJson, currentPathSegments = []) {
|
|
2
|
+
let resultArgTypes = {};
|
|
3
|
+
for (const field of fieldsJson) {
|
|
4
|
+
// storybook doesn't support nested controls, so emulate our nested
|
|
5
|
+
// structure with group1.group2.field structure
|
|
6
|
+
const fullFieldName = [...currentPathSegments, field.name].join('.');
|
|
7
|
+
// should this definition of fieldType => argType live next to fields in cms-components?
|
|
8
|
+
switch (field.type) {
|
|
9
|
+
case 'group': {
|
|
10
|
+
if (!field.children) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
const groupResult = getFieldsArgTypes(field.children, [
|
|
14
|
+
...currentPathSegments,
|
|
15
|
+
field.name,
|
|
16
|
+
]);
|
|
17
|
+
resultArgTypes = {
|
|
18
|
+
...resultArgTypes,
|
|
19
|
+
...groupResult,
|
|
20
|
+
};
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case 'boolean': {
|
|
24
|
+
resultArgTypes[fullFieldName] = {
|
|
25
|
+
control: 'boolean',
|
|
26
|
+
defaultValue: field.default,
|
|
27
|
+
};
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case 'text': {
|
|
31
|
+
resultArgTypes[fullFieldName] = {
|
|
32
|
+
control: 'text',
|
|
33
|
+
defaultValue: field.default,
|
|
34
|
+
};
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case 'number': {
|
|
38
|
+
resultArgTypes[fullFieldName] = {
|
|
39
|
+
control: 'number',
|
|
40
|
+
defaultValue: field.default,
|
|
41
|
+
};
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
default: {
|
|
45
|
+
resultArgTypes[fullFieldName] = {
|
|
46
|
+
control: 'object',
|
|
47
|
+
defaultValue: field.default,
|
|
48
|
+
};
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return resultArgTypes;
|
|
54
|
+
}
|