@hubspot/cms-dev-server 0.18.20 → 0.18.22
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/.DS_Store +0 -0
- package/dist/App.js +168 -0
- package/dist/App.js.map +7 -0
- package/dist/_.._/.DS_Store +0 -0
- package/dist/_.._/app/serverEntry.js +8 -0
- package/dist/_.._/app/serverEntry.js.map +7 -0
- package/dist/clientEntry.css +2 -0
- package/dist/clientEntry.css.map +7 -0
- package/dist/clientEntry.js +168 -0
- package/dist/clientEntry.js.map +7 -0
- package/dist/components.json +20 -0
- package/dist/fonts/LexendDeca-Bold-PSGSBIWW.woff2 +0 -0
- package/dist/fonts/LexendDeca-Bold.woff2 +0 -0
- package/dist/fonts/LexendDeca-Light-IDG5XLZG.woff2 +0 -0
- package/dist/fonts/LexendDeca-Light.woff2 +0 -0
- package/dist/fonts/LexendDeca-Medium-ZCTJP7FU.woff2 +0 -0
- package/dist/fonts/LexendDeca-Medium.woff2 +0 -0
- package/dist/fonts/LexendDeca-SemiBold-LCAJGQDV.woff2 +0 -0
- package/dist/fonts/LexendDeca-SemiBold.woff2 +0 -0
- package/dist/generateJsonFromJsx.js.map +7 -0
- package/dist/index.css +2 -0
- package/dist/index.css.map +7 -0
- package/dist/index.html +14 -0
- package/dist/index.js +220 -213
- package/dist/index.js.map +7 -0
- package/dist/internalSsr.js.map +7 -0
- package/dist/island-runtime.js.map +7 -0
- package/dist/postcss.config.js +6 -0
- package/dist/run.js +237 -216
- package/dist/run.js.map +7 -0
- package/dist/storybook/index.js.map +7 -0
- package/dist/storybook-main/main.js.map +7 -0
- package/dist/storybook-main/preview.js.map +7 -0
- package/dist/tailwind.config.js +67 -0
- package/package.json +5 -3
- package/types/constants/errors.d.ts +5 -0
- package/types/createAppServer.d.ts +2 -2
- package/types/createAppViteConfig.d.ts +2 -0
- package/types/lib/cli.d.ts +22 -0
- package/types/lib/cliUtils.d.ts +14 -0
- package/types/lib/getDevServerUIData.d.ts +2 -2
- package/types/routes/api.d.ts +2 -0
- package/types/routes/appServerRoutes.d.ts +5 -0
- package/types/routes/createDevServerRoutes.d.ts +6 -1
- package/types/storybook-main/preview.d.ts +9 -0
- package/types/lib/renderModuleJson.d.ts +0 -4
package/dist/run.js
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
// src/lib/instrument.ts
|
|
4
|
+
import * as Sentry from "@sentry/node";
|
|
5
|
+
import { nodeProfilingIntegration } from "@sentry/profiling-node";
|
|
6
|
+
var isDev = process.env.NODE_ENV === "development";
|
|
7
|
+
var DSN_KEY = "f50d34a51498b37c8da9e9cba13be20a";
|
|
8
|
+
var domain = isDev ? "exceptions-na1.hubspotqa.com" : "exceptions-na1.hubspot.com";
|
|
9
|
+
var SENTRY_DSN = `https://${DSN_KEY}@${domain}/v2/1`;
|
|
10
|
+
Sentry.init({
|
|
11
|
+
dsn: SENTRY_DSN,
|
|
12
|
+
integrations: [nodeProfilingIntegration()],
|
|
13
|
+
tracesSampleRate: 1
|
|
14
|
+
// profilesSampleRate: 1.0,
|
|
15
|
+
});
|
|
16
|
+
|
|
3
17
|
// src/lib/cli.ts
|
|
4
18
|
import { resolve, join } from "path";
|
|
5
19
|
import { existsSync } from "fs";
|
|
@@ -748,7 +762,7 @@ async function buildThemePreviewOptions(webRoot2, isUsingLocalWorkspace = false)
|
|
|
748
762
|
// src/createDevServer.ts
|
|
749
763
|
import path15 from "path";
|
|
750
764
|
import url2 from "url";
|
|
751
|
-
import
|
|
765
|
+
import express2 from "express";
|
|
752
766
|
import http3 from "http";
|
|
753
767
|
import bodyParser from "body-parser";
|
|
754
768
|
import { spawn as spawn2 } from "child_process";
|
|
@@ -756,7 +770,7 @@ import { normalizePath as normalizePath9 } from "vite";
|
|
|
756
770
|
import { Transform } from "stream";
|
|
757
771
|
|
|
758
772
|
// src/routes/createDevServerRoutes.ts
|
|
759
|
-
import { Router, urlencoded } from "express";
|
|
773
|
+
import { Router as Router2, urlencoded } from "express";
|
|
760
774
|
import { createProxyMiddleware } from "http-proxy-middleware";
|
|
761
775
|
|
|
762
776
|
// src/routes/partial.ts
|
|
@@ -2081,7 +2095,7 @@ function trackUsage(action) {
|
|
|
2081
2095
|
eventName: EVENT_NAME,
|
|
2082
2096
|
action,
|
|
2083
2097
|
nodeVersion: getNodeVersionData(),
|
|
2084
|
-
version: "0.18.
|
|
2098
|
+
version: "0.18.22",
|
|
2085
2099
|
os: getPlatform()
|
|
2086
2100
|
};
|
|
2087
2101
|
const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -4625,12 +4639,150 @@ function buildTemplateIndex() {
|
|
|
4625
4639
|
`);
|
|
4626
4640
|
}
|
|
4627
4641
|
|
|
4642
|
+
// src/routes/createDevServerRoutes.ts
|
|
4643
|
+
import fs4 from "node:fs/promises";
|
|
4644
|
+
|
|
4645
|
+
// src/lib/getDevServerUIData.ts
|
|
4646
|
+
import path12 from "path";
|
|
4647
|
+
import { normalizePath as normalizePath8 } from "vite";
|
|
4648
|
+
function mapReactModules(modules, themeWebRoot, viteServer) {
|
|
4649
|
+
return Promise.all(
|
|
4650
|
+
modules.moduleNames.map(async (name, index) => {
|
|
4651
|
+
const modulePath = normalizePath8(
|
|
4652
|
+
path12.resolve(themeWebRoot, "components/modules/", name)
|
|
4653
|
+
);
|
|
4654
|
+
const fieldsJson = await renderModuleFieldsJson_default(viteServer, modulePath);
|
|
4655
|
+
return {
|
|
4656
|
+
name,
|
|
4657
|
+
type: "react" /* REACT */,
|
|
4658
|
+
subPath: modules.moduleSubpaths[index],
|
|
4659
|
+
nameWithExtension: modules.moduleNamesWithExtension[index],
|
|
4660
|
+
extension: modules.moduleExtensions[index],
|
|
4661
|
+
fieldsJson
|
|
4662
|
+
};
|
|
4663
|
+
})
|
|
4664
|
+
);
|
|
4665
|
+
}
|
|
4666
|
+
function normalizeHubLModules(modules) {
|
|
4667
|
+
return modules.map((module) => ({
|
|
4668
|
+
name: module.name,
|
|
4669
|
+
type: "hubl" /* HUBL */,
|
|
4670
|
+
subPath: `@projects/${module.path.split("/@projects/")[1] || module.path}`,
|
|
4671
|
+
nameWithExtension: module.filename,
|
|
4672
|
+
fieldsJson: module.fields
|
|
4673
|
+
}));
|
|
4674
|
+
}
|
|
4675
|
+
function normalizePartialsData(partialData) {
|
|
4676
|
+
return partialData.partialNames.map((name, index) => ({
|
|
4677
|
+
name,
|
|
4678
|
+
subPath: partialData.partialSubpaths[index]
|
|
4679
|
+
}));
|
|
4680
|
+
}
|
|
4681
|
+
function normalizeTemplatesData(templates) {
|
|
4682
|
+
return templates.map((template) => ({
|
|
4683
|
+
name: template.displayName || template.label,
|
|
4684
|
+
subPath: `@projects/${template.path.split("/@projects/")[1] || template.path}`
|
|
4685
|
+
}));
|
|
4686
|
+
}
|
|
4687
|
+
async function getDevServerUIData(reqLocals, viteServer) {
|
|
4688
|
+
const {
|
|
4689
|
+
themeWebRoot,
|
|
4690
|
+
authedEnv,
|
|
4691
|
+
authedPortalId,
|
|
4692
|
+
projectName,
|
|
4693
|
+
localPreviewToken,
|
|
4694
|
+
webRootProjectComponentFolder
|
|
4695
|
+
} = reqLocals;
|
|
4696
|
+
const modulesData = findAllModulesInRoot(themeWebRoot);
|
|
4697
|
+
const partialsData = findAllPartialsInRoot(themeWebRoot);
|
|
4698
|
+
const reactModules = await mapReactModules(
|
|
4699
|
+
modulesData,
|
|
4700
|
+
themeWebRoot,
|
|
4701
|
+
viteServer
|
|
4702
|
+
);
|
|
4703
|
+
let hubLModuleData = { objects: [] };
|
|
4704
|
+
let hubLTemplateData = { objects: [] };
|
|
4705
|
+
if (authedPortalId) {
|
|
4706
|
+
hubLModuleData = await fetchHubLModules(authedPortalId, localPreviewToken);
|
|
4707
|
+
hubLTemplateData = await fetchPreviewTemplates(
|
|
4708
|
+
authedPortalId,
|
|
4709
|
+
localPreviewToken
|
|
4710
|
+
);
|
|
4711
|
+
}
|
|
4712
|
+
const hubLTemplates = (hubLTemplateData == null ? void 0 : hubLTemplateData.objects.filter(
|
|
4713
|
+
(template) => isCodedFile(template.filename)
|
|
4714
|
+
)) || [];
|
|
4715
|
+
const mappedHubLModules = normalizeHubLModules((hubLModuleData == null ? void 0 : hubLModuleData.objects) || []);
|
|
4716
|
+
return {
|
|
4717
|
+
authedPortalId,
|
|
4718
|
+
authedEnv,
|
|
4719
|
+
projectName,
|
|
4720
|
+
modulesData: reactModules,
|
|
4721
|
+
partialsData: normalizePartialsData(partialsData),
|
|
4722
|
+
hubLModules: mappedHubLModules || [],
|
|
4723
|
+
hubLTemplates: normalizeTemplatesData(hubLTemplates),
|
|
4724
|
+
themeWebRoot,
|
|
4725
|
+
webRootProjectComponentFolder
|
|
4726
|
+
};
|
|
4727
|
+
}
|
|
4728
|
+
var getDevServerUIData_default = getDevServerUIData;
|
|
4729
|
+
|
|
4730
|
+
// src/routes/createAppServerRoutes.ts
|
|
4731
|
+
import { Router } from "express";
|
|
4732
|
+
import { spawn } from "child_process";
|
|
4733
|
+
function getOpenCommand() {
|
|
4734
|
+
switch (process.platform) {
|
|
4735
|
+
case "darwin":
|
|
4736
|
+
return "open";
|
|
4737
|
+
case "win32":
|
|
4738
|
+
return "start";
|
|
4739
|
+
default:
|
|
4740
|
+
return "xdg-open";
|
|
4741
|
+
}
|
|
4742
|
+
}
|
|
4743
|
+
async function handleGetModulePages(req, res, next) {
|
|
4744
|
+
const { path: path16, portalId } = req.query;
|
|
4745
|
+
if (!path16 || !portalId) {
|
|
4746
|
+
return res.status(400).json({ error: "Missing required parameters" });
|
|
4747
|
+
}
|
|
4748
|
+
try {
|
|
4749
|
+
const data = await fetchModulePageDependencies(
|
|
4750
|
+
Number(portalId),
|
|
4751
|
+
path16
|
|
4752
|
+
);
|
|
4753
|
+
res.json(data);
|
|
4754
|
+
} catch (err) {
|
|
4755
|
+
next(err);
|
|
4756
|
+
}
|
|
4757
|
+
}
|
|
4758
|
+
function handleOpenFile(req, res, next) {
|
|
4759
|
+
const { path: path16 } = req.query;
|
|
4760
|
+
if (!path16) {
|
|
4761
|
+
return res.status(400).json({ error: "Missing required parameters" });
|
|
4762
|
+
}
|
|
4763
|
+
try {
|
|
4764
|
+
const command = getOpenCommand();
|
|
4765
|
+
spawn(command, [path16], { detached: true }).unref();
|
|
4766
|
+
res.sendStatus(200);
|
|
4767
|
+
} catch (err) {
|
|
4768
|
+
next(err);
|
|
4769
|
+
}
|
|
4770
|
+
}
|
|
4771
|
+
function createAppServerRoutes() {
|
|
4772
|
+
const router = Router();
|
|
4773
|
+
router.get("/module-pages", handleGetModulePages);
|
|
4774
|
+
router.get("/open-file", handleOpenFile);
|
|
4775
|
+
return router;
|
|
4776
|
+
}
|
|
4777
|
+
var createAppServerRoutes_default = createAppServerRoutes;
|
|
4778
|
+
|
|
4628
4779
|
// src/routes/createDevServerRoutes.ts
|
|
4629
4780
|
var STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(
|
|
4630
|
-
(
|
|
4781
|
+
(domain2) => `storybook.${domain2}`
|
|
4631
4782
|
);
|
|
4632
|
-
var createDevServerRoutes = async (viteServer, storybookPort) => {
|
|
4633
|
-
const devServerApp =
|
|
4783
|
+
var createDevServerRoutes = async (viteServer, storybookPort, appServerConfig) => {
|
|
4784
|
+
const devServerApp = Router2();
|
|
4785
|
+
const { appServer, reqLocals, appWebRoot } = appServerConfig || {};
|
|
4634
4786
|
devServerApp.use((request2, response, next) => {
|
|
4635
4787
|
const { method, url: url3, hostname } = request2;
|
|
4636
4788
|
debug(`${method}:${hostname}${url3}`);
|
|
@@ -4647,8 +4799,39 @@ var createDevServerRoutes = async (viteServer, storybookPort) => {
|
|
|
4647
4799
|
)
|
|
4648
4800
|
);
|
|
4649
4801
|
}
|
|
4650
|
-
devServerApp.use(viteServer.middlewares);
|
|
4651
4802
|
devServerApp.use(urlencoded());
|
|
4803
|
+
if (appServer) {
|
|
4804
|
+
devServerApp.use(appServer.middlewares);
|
|
4805
|
+
devServerApp.use(viteServer.middlewares);
|
|
4806
|
+
devServerApp.use("/api", createAppServerRoutes_default());
|
|
4807
|
+
devServerApp.get("/", async (req, res) => {
|
|
4808
|
+
try {
|
|
4809
|
+
const initialProps = await getDevServerUIData_default(reqLocals, viteServer);
|
|
4810
|
+
const url3 = req.originalUrl.replace("/", "");
|
|
4811
|
+
let template = await fs4.readFile(`${appWebRoot}/index.html`, "utf-8");
|
|
4812
|
+
template = await appServer.transformIndexHtml(url3, template);
|
|
4813
|
+
const { render } = await appServer.ssrLoadModule(
|
|
4814
|
+
`${appWebRoot}/serverEntry.tsx`
|
|
4815
|
+
);
|
|
4816
|
+
const rendered = await render(initialProps);
|
|
4817
|
+
const html = template.replace(`<!--app-head-->`, rendered.head ?? "").replace(`<!--app-html-->`, rendered.html ?? "").replace(
|
|
4818
|
+
`<!--app-script-->`,
|
|
4819
|
+
`<script>window.__hsInitialProps = ${JSON.stringify(
|
|
4820
|
+
initialProps
|
|
4821
|
+
)}</script>` ?? ""
|
|
4822
|
+
);
|
|
4823
|
+
res.status(200).set({ "Content-Type": "text/html" }).send(html);
|
|
4824
|
+
} catch (e) {
|
|
4825
|
+
appServer == null ? void 0 : appServer.ssrFixStacktrace(e);
|
|
4826
|
+
console.log(e.stack);
|
|
4827
|
+
res.status(500).end(e.stack);
|
|
4828
|
+
}
|
|
4829
|
+
});
|
|
4830
|
+
devServerApp.get("/legacy", homeRouteHandler_default);
|
|
4831
|
+
} else {
|
|
4832
|
+
devServerApp.use(viteServer.middlewares);
|
|
4833
|
+
devServerApp.get("/", homeRouteHandler_default);
|
|
4834
|
+
}
|
|
4652
4835
|
devServerApp.get("/proxy", proxyPathPageRouteHandler);
|
|
4653
4836
|
devServerApp.get("/partials/", linksToAllPartialsRouteHandler_default);
|
|
4654
4837
|
devServerApp.get("/partial/:partial", partial_default);
|
|
@@ -4667,7 +4850,6 @@ var createDevServerRoutes = async (viteServer, storybookPort) => {
|
|
|
4667
4850
|
devServerApp.get("/template/:templatePath(*)", templateRouteHandler);
|
|
4668
4851
|
devServerApp.all("/hs/serverless/*", proxyServerlessRequest);
|
|
4669
4852
|
devServerApp.all("/_hcms/api/*", proxyServerlessRequest);
|
|
4670
|
-
devServerApp.get("/", homeRouteHandler_default);
|
|
4671
4853
|
devServerApp.get("/*", proxyPathPageResourceRedirect);
|
|
4672
4854
|
devServerApp.get("/*", proxyPageResourceRedirect);
|
|
4673
4855
|
devServerApp.post("/*", proxyPageResourceRedirect);
|
|
@@ -4685,7 +4867,7 @@ import net from "net";
|
|
|
4685
4867
|
import express from "express";
|
|
4686
4868
|
|
|
4687
4869
|
// src/shadowDevServer/createShadowDevServerRoutes.ts
|
|
4688
|
-
import { Router as
|
|
4870
|
+
import { Router as Router3 } from "express";
|
|
4689
4871
|
import { getAccountId as getAccountId3 } from "@hubspot/local-dev-lib/config";
|
|
4690
4872
|
import cors from "cors";
|
|
4691
4873
|
function getShadowDevServerCheckHandler(devServerPort, themePath) {
|
|
@@ -4743,7 +4925,7 @@ ${error.stack}`
|
|
|
4743
4925
|
};
|
|
4744
4926
|
}
|
|
4745
4927
|
async function createShadowDevServerRoutes(devServerPort, themePath) {
|
|
4746
|
-
const shadowDevServerRoutes =
|
|
4928
|
+
const shadowDevServerRoutes = Router3();
|
|
4747
4929
|
shadowDevServerRoutes.get(
|
|
4748
4930
|
"/check-if-local-dev-server",
|
|
4749
4931
|
cors(),
|
|
@@ -4895,161 +5077,23 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
4895
5077
|
var createViteDevServer_default = createViteDevServer;
|
|
4896
5078
|
|
|
4897
5079
|
// src/createAppServer.ts
|
|
4898
|
-
import
|
|
4899
|
-
|
|
4900
|
-
|
|
5080
|
+
import {
|
|
5081
|
+
createServer as createViteServer2
|
|
5082
|
+
} from "vite";
|
|
4901
5083
|
import { default as react2 } from "@vitejs/plugin-react";
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
import path12 from "path";
|
|
4905
|
-
import { normalizePath as normalizePath8 } from "vite";
|
|
4906
|
-
function mapReactModules(modules, themeWebRoot, viteServer) {
|
|
4907
|
-
return Promise.all(
|
|
4908
|
-
modules.moduleNames.map(async (name, index) => {
|
|
4909
|
-
const modulePath = normalizePath8(
|
|
4910
|
-
path12.resolve(themeWebRoot, "components/modules/", name)
|
|
4911
|
-
);
|
|
4912
|
-
const fieldsJson = await renderModuleFieldsJson_default(viteServer, modulePath);
|
|
4913
|
-
return {
|
|
4914
|
-
name,
|
|
4915
|
-
type: "react" /* REACT */,
|
|
4916
|
-
subPath: modules.moduleSubpaths[index],
|
|
4917
|
-
nameWithExtension: modules.moduleNamesWithExtension[index],
|
|
4918
|
-
extension: modules.moduleExtensions[index],
|
|
4919
|
-
fieldsJson
|
|
4920
|
-
};
|
|
4921
|
-
})
|
|
4922
|
-
);
|
|
4923
|
-
}
|
|
4924
|
-
function normalizeHubLModules(modules) {
|
|
4925
|
-
return modules.map((module) => ({
|
|
4926
|
-
name: module.name,
|
|
4927
|
-
type: "hubl" /* HUBL */,
|
|
4928
|
-
subPath: `@projects/${module.path.split("/@projects/")[1] || module.path}`,
|
|
4929
|
-
nameWithExtension: module.filename,
|
|
4930
|
-
fieldsJson: module.fields
|
|
4931
|
-
}));
|
|
4932
|
-
}
|
|
4933
|
-
function normalizePartialsData(partialData) {
|
|
4934
|
-
return partialData.partialNames.map((name, index) => ({
|
|
4935
|
-
name,
|
|
4936
|
-
subPath: partialData.partialSubpaths[index]
|
|
4937
|
-
}));
|
|
4938
|
-
}
|
|
4939
|
-
function normalizeTemplatesData(templates) {
|
|
4940
|
-
return templates.map((template) => ({
|
|
4941
|
-
name: template.displayName || template.label,
|
|
4942
|
-
subPath: `@projects/${template.path.split("/@projects/")[1] || template.path}`
|
|
4943
|
-
}));
|
|
4944
|
-
}
|
|
4945
|
-
async function getDevServerUIData(reqLocals) {
|
|
4946
|
-
const {
|
|
4947
|
-
themeWebRoot,
|
|
4948
|
-
authedEnv,
|
|
4949
|
-
authedPortalId,
|
|
4950
|
-
projectName,
|
|
4951
|
-
localPreviewToken,
|
|
4952
|
-
webRootProjectComponentFolder,
|
|
4953
|
-
viteServer
|
|
4954
|
-
} = reqLocals;
|
|
4955
|
-
const modulesData = findAllModulesInRoot(themeWebRoot);
|
|
4956
|
-
const partialsData = findAllPartialsInRoot(themeWebRoot);
|
|
4957
|
-
const reactModules = await mapReactModules(
|
|
4958
|
-
modulesData,
|
|
4959
|
-
themeWebRoot,
|
|
4960
|
-
viteServer
|
|
4961
|
-
);
|
|
4962
|
-
let hubLModuleData = { objects: [] };
|
|
4963
|
-
let hubLTemplateData = { objects: [] };
|
|
4964
|
-
if (authedPortalId) {
|
|
4965
|
-
hubLModuleData = await fetchHubLModules(authedPortalId, localPreviewToken);
|
|
4966
|
-
hubLTemplateData = await fetchPreviewTemplates(
|
|
4967
|
-
authedPortalId,
|
|
4968
|
-
localPreviewToken
|
|
4969
|
-
);
|
|
4970
|
-
}
|
|
4971
|
-
const hubLTemplates = (hubLTemplateData == null ? void 0 : hubLTemplateData.objects.filter(
|
|
4972
|
-
(template) => isCodedFile(template.filename)
|
|
4973
|
-
)) || [];
|
|
4974
|
-
const mappedHubLModules = normalizeHubLModules((hubLModuleData == null ? void 0 : hubLModuleData.objects) || []);
|
|
4975
|
-
return {
|
|
4976
|
-
authedPortalId,
|
|
4977
|
-
authedEnv,
|
|
4978
|
-
projectName,
|
|
4979
|
-
modulesData: reactModules,
|
|
4980
|
-
partialsData: normalizePartialsData(partialsData),
|
|
4981
|
-
hubLModules: mappedHubLModules || [],
|
|
4982
|
-
hubLTemplates: normalizeTemplatesData(hubLTemplates),
|
|
4983
|
-
themeWebRoot,
|
|
4984
|
-
webRootProjectComponentFolder
|
|
4985
|
-
};
|
|
4986
|
-
}
|
|
4987
|
-
var getDevServerUIData_default = getDevServerUIData;
|
|
4988
|
-
|
|
4989
|
-
// src/routes/createAppServerRoutes.ts
|
|
4990
|
-
import { Router as Router3 } from "express";
|
|
4991
|
-
import { spawn } from "child_process";
|
|
4992
|
-
function getOpenCommand() {
|
|
4993
|
-
switch (process.platform) {
|
|
4994
|
-
case "darwin":
|
|
4995
|
-
return "open";
|
|
4996
|
-
case "win32":
|
|
4997
|
-
return "start";
|
|
4998
|
-
default:
|
|
4999
|
-
return "xdg-open";
|
|
5000
|
-
}
|
|
5001
|
-
}
|
|
5002
|
-
async function handleGetModulePages(req, res, next) {
|
|
5003
|
-
const { path: path16, portalId } = req.query;
|
|
5004
|
-
if (!path16 || !portalId) {
|
|
5005
|
-
return res.status(400).json({ error: "Missing required parameters" });
|
|
5006
|
-
}
|
|
5007
|
-
try {
|
|
5008
|
-
const data = await fetchModulePageDependencies(
|
|
5009
|
-
Number(portalId),
|
|
5010
|
-
path16
|
|
5011
|
-
);
|
|
5012
|
-
res.json(data);
|
|
5013
|
-
} catch (err) {
|
|
5014
|
-
next(err);
|
|
5015
|
-
}
|
|
5016
|
-
}
|
|
5017
|
-
function handleOpenFile(req, res, next) {
|
|
5018
|
-
const { path: path16 } = req.query;
|
|
5019
|
-
if (!path16) {
|
|
5020
|
-
return res.status(400).json({ error: "Missing required parameters" });
|
|
5021
|
-
}
|
|
5022
|
-
try {
|
|
5023
|
-
const command = getOpenCommand();
|
|
5024
|
-
spawn(command, [path16], { detached: true }).unref();
|
|
5025
|
-
res.sendStatus(200);
|
|
5026
|
-
} catch (err) {
|
|
5027
|
-
next(err);
|
|
5028
|
-
}
|
|
5029
|
-
}
|
|
5030
|
-
function createAppServerRoutes() {
|
|
5031
|
-
const router = Router3();
|
|
5032
|
-
router.get("/module-pages", handleGetModulePages);
|
|
5033
|
-
router.get("/open-file", handleOpenFile);
|
|
5034
|
-
return router;
|
|
5035
|
-
}
|
|
5036
|
-
|
|
5037
|
-
// src/createAppServer.ts
|
|
5038
|
-
async function createAppServer(webRoot2, reqLocals, port) {
|
|
5039
|
-
const app = express2();
|
|
5040
|
-
const origin = `http://hslocal.net:${port}`;
|
|
5084
|
+
async function createAppServer(appWebRoot, port, sslEnabled) {
|
|
5085
|
+
const origin = process.env.VITE_ORIGIN ?? (sslEnabled ? `https://hslocal.net:${port}` : `http://hslocal.net:${port}`);
|
|
5041
5086
|
const viteConfig = {
|
|
5042
5087
|
server: {
|
|
5043
5088
|
middlewareMode: true,
|
|
5044
5089
|
host: "hslocal.net",
|
|
5045
5090
|
origin,
|
|
5046
5091
|
hmr: {
|
|
5047
|
-
|
|
5048
|
-
host: "hslocal.net"
|
|
5092
|
+
protocol: sslEnabled ? "wss" : void 0
|
|
5049
5093
|
}
|
|
5050
5094
|
},
|
|
5051
5095
|
appType: "custom",
|
|
5052
|
-
root:
|
|
5096
|
+
root: appWebRoot,
|
|
5053
5097
|
ssr: {
|
|
5054
5098
|
noExternal: "@hubspot/cms-components"
|
|
5055
5099
|
},
|
|
@@ -5057,7 +5101,7 @@ async function createAppServer(webRoot2, reqLocals, port) {
|
|
|
5057
5101
|
conditions: ["server"],
|
|
5058
5102
|
dedupe: ["react", "react-dom", "@hubspot/cms-components", "styled-jsx"],
|
|
5059
5103
|
alias: {
|
|
5060
|
-
"@":
|
|
5104
|
+
"@": appWebRoot
|
|
5061
5105
|
}
|
|
5062
5106
|
},
|
|
5063
5107
|
optimizeDeps: {
|
|
@@ -5077,48 +5121,12 @@ async function createAppServer(webRoot2, reqLocals, port) {
|
|
|
5077
5121
|
resolveIslandPlugin()
|
|
5078
5122
|
],
|
|
5079
5123
|
css: {
|
|
5080
|
-
postcss:
|
|
5124
|
+
postcss: appWebRoot
|
|
5081
5125
|
},
|
|
5082
|
-
envDir:
|
|
5126
|
+
envDir: appWebRoot,
|
|
5083
5127
|
envPrefix: "HS_"
|
|
5084
5128
|
};
|
|
5085
|
-
|
|
5086
|
-
app.use("/api", createAppServerRoutes());
|
|
5087
|
-
app.use(viteServer.middlewares);
|
|
5088
|
-
app.get("/*", async (req, res) => {
|
|
5089
|
-
try {
|
|
5090
|
-
const initialProps = await getDevServerUIData_default({
|
|
5091
|
-
...reqLocals,
|
|
5092
|
-
viteServer
|
|
5093
|
-
});
|
|
5094
|
-
const url3 = req.originalUrl.replace("/", "");
|
|
5095
|
-
let template = await fs4.readFile(`${webRoot2}/index.html`, "utf-8");
|
|
5096
|
-
template = await viteServer.transformIndexHtml(url3, template);
|
|
5097
|
-
const { render } = await viteServer.ssrLoadModule(
|
|
5098
|
-
`${webRoot2}/serverEntry.tsx`
|
|
5099
|
-
);
|
|
5100
|
-
const rendered = await render(initialProps);
|
|
5101
|
-
const html = template.replace(`<!--app-head-->`, rendered.head ?? "").replace(`<!--app-html-->`, rendered.html ?? "").replace(
|
|
5102
|
-
`<!--app-script-->`,
|
|
5103
|
-
`<script>window.__hsInitialProps = ${JSON.stringify(
|
|
5104
|
-
initialProps
|
|
5105
|
-
)}</script>` ?? ""
|
|
5106
|
-
);
|
|
5107
|
-
res.status(200).set({ "Content-Type": "text/html" }).send(html);
|
|
5108
|
-
} catch (e) {
|
|
5109
|
-
viteServer == null ? void 0 : viteServer.ssrFixStacktrace(e);
|
|
5110
|
-
console.log(e.stack);
|
|
5111
|
-
res.status(500).end(e.stack);
|
|
5112
|
-
}
|
|
5113
|
-
});
|
|
5114
|
-
app.use((err, req, res, __next) => {
|
|
5115
|
-
console.error("API Error:", err);
|
|
5116
|
-
res.status(500).json({ error: "Internal server error" });
|
|
5117
|
-
});
|
|
5118
|
-
app.listen(port, () => {
|
|
5119
|
-
console.log(`Server started at http://localhost:${port}`);
|
|
5120
|
-
});
|
|
5121
|
-
return app;
|
|
5129
|
+
return createViteServer2(viteConfig);
|
|
5122
5130
|
}
|
|
5123
5131
|
var createAppServer_default = createAppServer;
|
|
5124
5132
|
|
|
@@ -5273,8 +5281,8 @@ async function fetchDomains(portalId) {
|
|
|
5273
5281
|
}
|
|
5274
5282
|
async function fetchWebsiteDomainNames(portalId) {
|
|
5275
5283
|
const domains = await fetchDomains(portalId);
|
|
5276
|
-
const filteredDomains = domains.filter((
|
|
5277
|
-
return
|
|
5284
|
+
const filteredDomains = domains.filter((domain2) => {
|
|
5285
|
+
return domain2.isUsedForBlogPost || domain2.isUsedForSitePage || domain2.isUsedForLandingPage;
|
|
5278
5286
|
});
|
|
5279
5287
|
const domainNames = filteredDomains.map((r) => r.domain);
|
|
5280
5288
|
return domainNames;
|
|
@@ -5881,7 +5889,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
5881
5889
|
const httpsCert = viteHTTPSConfig ? viteHTTPSConfig.cert : null;
|
|
5882
5890
|
const projectName = projectConfigPath ? getProjectNameFromHSConfig(projectConfigPath) : "";
|
|
5883
5891
|
const httpServers = [];
|
|
5884
|
-
const expressServer =
|
|
5892
|
+
const expressServer = express2();
|
|
5885
5893
|
expressServer.locals.devServerHost = "hslocal.net";
|
|
5886
5894
|
expressServer.locals.devServerPort = PORT;
|
|
5887
5895
|
expressServer.locals.webRoot = webRoot2;
|
|
@@ -5897,9 +5905,39 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
5897
5905
|
expressServer.locals.domainsToProxy = domainsToProxy;
|
|
5898
5906
|
expressServer.locals.localPreviewToken = _localPreviewToken;
|
|
5899
5907
|
expressServer.use(bodyParser.json());
|
|
5908
|
+
let appServerConfig = null;
|
|
5909
|
+
if (showUI2) {
|
|
5910
|
+
const appWebRoot = path15.join(
|
|
5911
|
+
path15.dirname(url2.fileURLToPath(import.meta.url)),
|
|
5912
|
+
"../app"
|
|
5913
|
+
);
|
|
5914
|
+
const reqLocals = {
|
|
5915
|
+
themeWebRoot: absoluteWebRoot,
|
|
5916
|
+
authedPortalId,
|
|
5917
|
+
authedEnv,
|
|
5918
|
+
authedHublet,
|
|
5919
|
+
projectName,
|
|
5920
|
+
webRootProjectComponentFolder,
|
|
5921
|
+
localPreviewToken: _localPreviewToken
|
|
5922
|
+
};
|
|
5923
|
+
const appServer = await createAppServer_default(
|
|
5924
|
+
appWebRoot,
|
|
5925
|
+
PORT,
|
|
5926
|
+
sslEnabledOption2
|
|
5927
|
+
);
|
|
5928
|
+
appServerConfig = {
|
|
5929
|
+
appServer,
|
|
5930
|
+
reqLocals,
|
|
5931
|
+
appWebRoot
|
|
5932
|
+
};
|
|
5933
|
+
}
|
|
5900
5934
|
expressServer.use(
|
|
5901
5935
|
BASE_PATH,
|
|
5902
|
-
await createDevServerRoutes_default(
|
|
5936
|
+
await createDevServerRoutes_default(
|
|
5937
|
+
viteServer,
|
|
5938
|
+
storybook2 ? STORYBOOK_PORT : null,
|
|
5939
|
+
appServerConfig
|
|
5940
|
+
)
|
|
5903
5941
|
);
|
|
5904
5942
|
if (sslEnabledOption2) {
|
|
5905
5943
|
if (httpsKey && httpsCert) {
|
|
@@ -5940,23 +5978,6 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
5940
5978
|
HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectComponentPath} (at ${protocol}://hslocal.net:${PORT}${extraServerInfo})
|
|
5941
5979
|
`
|
|
5942
5980
|
);
|
|
5943
|
-
if (showUI2) {
|
|
5944
|
-
const appWebRoot = path15.join(
|
|
5945
|
-
path15.dirname(url2.fileURLToPath(import.meta.url)),
|
|
5946
|
-
"../app"
|
|
5947
|
-
);
|
|
5948
|
-
const reqLocals = {
|
|
5949
|
-
themeWebRoot: absoluteWebRoot,
|
|
5950
|
-
authedPortalId,
|
|
5951
|
-
authedEnv,
|
|
5952
|
-
authedHublet,
|
|
5953
|
-
projectName,
|
|
5954
|
-
webRootProjectComponentFolder,
|
|
5955
|
-
localPreviewToken: _localPreviewToken
|
|
5956
|
-
};
|
|
5957
|
-
const appServer = await createAppServer_default(appWebRoot, reqLocals, PORT + 1);
|
|
5958
|
-
httpServers.push(appServer);
|
|
5959
|
-
}
|
|
5960
5981
|
if (storybook2) {
|
|
5961
5982
|
const packageRoot = path15.dirname(url2.fileURLToPath(import.meta.url));
|
|
5962
5983
|
const configPath = path15.resolve(packageRoot, "./storybook-main");
|