Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: CLI, CORS does not allow synchronization in certain scenarios (#4056)

Ivan Starkovcfe018a3e8d8
diff --git a/fixtures/ssg-netlify-by-project-id/.npmrc b/fixtures/ssg-netlify-by-project-id/.npmrc
new file mode 100644
index 0000000000..43ce02f127
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/.npmrc
@@ -0,0 +1,3 @@
+force=true
+# to support using NODE_OPTIONS for windows tests
+shell-emulator=true
diff --git a/fixtures/ssg-netlify-by-project-id/.webstudio/config.json b/fixtures/ssg-netlify-by-project-id/.webstudio/config.json
new file mode 100644
index 0000000000..e7c043528a
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/.webstudio/config.json
@@ -0,0 +1,3 @@
+{
+ "projectId": "8a7358b1-7de3-459d-b7b1-56dddfb6ce1e"
+}
diff --git a/fixtures/ssg-netlify-by-project-id/.webstudio/data.json b/fixtures/ssg-netlify-by-project-id/.webstudio/data.json
new file mode 100644
index 0000000000..f17781884c
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/.webstudio/data.json
@@ -0,0 +1,140 @@
+{
+ "build": {
+ "id": "1e6d93b8-3faa-4155-8628-dd31cafaf00e",
+ "projectId": "8a7358b1-7de3-459d-b7b1-56dddfb6ce1e",
+ "version": 2,
+ "createdAt": "2024-09-03T04:32:12.506",
+ "updatedAt": "2024-09-03T04:32:12.506+00:00",
+ "pages": {
+ "meta": {},
+ "homePage": {
+ "id": "Y60VJnVZMU_ifI0GnAR1N",
+ "name": "Home",
+ "title": "\"Home\"",
+ "rootInstanceId": "iavYtlaxaMTf7HB5DBf8e",
+ "systemDataSourceId": "XE93KQdVwfiA3TCf8hQAQ",
+ "meta": {},
+ "path": ""
+ },
+ "pages": [],
+ "folders": [
+ {
+ "id": "root",
+ "name": "Root",
+ "slug": "",
+ "children": ["Y60VJnVZMU_ifI0GnAR1N"]
+ }
+ ]
+ },
+ "breakpoints": [
+ [
+ "pTyOZEX5PG52onfyt3-Vg",
+ {
+ "id": "pTyOZEX5PG52onfyt3-Vg",
+ "label": "Base"
+ }
+ ],
+ [
+ "GzBytedsc258Pp7rh1hiD",
+ {
+ "id": "GzBytedsc258Pp7rh1hiD",
+ "label": "Tablet",
+ "maxWidth": 991
+ }
+ ],
+ [
+ "ugRM71O_Lm78kMKjkrtyz",
+ {
+ "id": "ugRM71O_Lm78kMKjkrtyz",
+ "label": "Mobile landscape",
+ "maxWidth": 767
+ }
+ ],
+ [
+ "NKdYAYw-oxmW8laNbpiwK",
+ {
+ "id": "NKdYAYw-oxmW8laNbpiwK",
+ "label": "Mobile portrait",
+ "maxWidth": 479
+ }
+ ]
+ ],
+ "styles": [],
+ "styleSources": [],
+ "styleSourceSelections": [],
+ "props": [],
+ "dataSources": [
+ [
+ "XE93KQdVwfiA3TCf8hQAQ",
+ {
+ "id": "XE93KQdVwfiA3TCf8hQAQ",
+ "scopeInstanceId": "iavYtlaxaMTf7HB5DBf8e",
+ "name": "system",
+ "type": "parameter"
+ }
+ ]
+ ],
+ "resources": [],
+ "instances": [
+ [
+ "iavYtlaxaMTf7HB5DBf8e",
+ {
+ "type": "instance",
+ "id": "iavYtlaxaMTf7HB5DBf8e",
+ "component": "Body",
+ "children": [
+ {
+ "type": "id",
+ "value": "cenhRks51W1S2iJMoGmqx"
+ }
+ ]
+ }
+ ],
+ [
+ "cenhRks51W1S2iJMoGmqx",
+ {
+ "type": "instance",
+ "id": "cenhRks51W1S2iJMoGmqx",
+ "component": "Heading",
+ "children": [
+ {
+ "type": "text",
+ "value": "FIXTURE-CLIENT-DO-NOT-TOUCH"
+ }
+ ]
+ }
+ ]
+ ],
+ "deployment": {
+ "destination": "saas",
+ "domains": [],
+ "projectDomain": "fixture-client-do-not-touch-wsmel"
+ }
+ },
+ "page": {
+ "id": "Y60VJnVZMU_ifI0GnAR1N",
+ "name": "Home",
+ "title": "\"Home\"",
+ "rootInstanceId": "iavYtlaxaMTf7HB5DBf8e",
+ "systemDataSourceId": "XE93KQdVwfiA3TCf8hQAQ",
+ "meta": {},
+ "path": ""
+ },
+ "pages": [
+ {
+ "id": "Y60VJnVZMU_ifI0GnAR1N",
+ "name": "Home",
+ "title": "\"Home\"",
+ "rootInstanceId": "iavYtlaxaMTf7HB5DBf8e",
+ "systemDataSourceId": "XE93KQdVwfiA3TCf8hQAQ",
+ "meta": {},
+ "path": ""
+ }
+ ],
+ "assets": [],
+ "user": {
+ "email": "[email protected]"
+ },
+ "projectDomain": "fixture-client-do-not-touch-wsmel",
+ "projectTitle": "FIXTURE-CLIENT-DO-NOT-TOUCH"
+}
diff --git a/fixtures/ssg-netlify-by-project-id/app/__generated__/$resources.sitemap.xml.ts b/fixtures/ssg-netlify-by-project-id/app/__generated__/$resources.sitemap.xml.ts
new file mode 100644
index 0000000000..3385a96eab
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/app/__generated__/$resources.sitemap.xml.ts
@@ -0,0 +1,6 @@
+export const sitemap = [
+ {
+ path: "/",
+ lastModified: "2024-09-03",
+ },
+];
diff --git a/fixtures/ssg-netlify-by-project-id/app/__generated__/_index.server.tsx b/fixtures/ssg-netlify-by-project-id/app/__generated__/_index.server.tsx
new file mode 100644
index 0000000000..abaf39176b
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/app/__generated__/_index.server.tsx
@@ -0,0 +1,39 @@
+/* eslint-disable */
+/* This is a auto generated file for building the project */
+
+import type { PageMeta } from "@webstudio-is/sdk";
+import type { System, ResourceRequest } from "@webstudio-is/sdk";
+export const getResources = (_props: { system: System }) => {
+ const _data = new Map<string, ResourceRequest>([]);
+ const _action = new Map<string, ResourceRequest>([]);
+ return { data: _data, action: _action };
+};
+
+export const getPageMeta = ({
+ system,
+ resources,
+}: {
+ system: System;
+ resources: Record<string, any>;
+}): PageMeta => {
+ return {
+ title: "Home",
+ description: undefined,
+ excludePageFromSearch: undefined,
+ language: undefined,
+ socialImageAssetName: undefined,
+ socialImageUrl: undefined,
+ status: undefined,
+ redirect: undefined,
+ custom: [],
+ };
+};
+
+type Params = Record<string, string | undefined>;
+export const getRemixParams = ({ ...params }: Params): Params => {
+ return params;
+};
+
+export const projectId = "8a7358b1-7de3-459d-b7b1-56dddfb6ce1e";
+
+export const contactEmail = "[email protected]";
diff --git a/fixtures/ssg-netlify-by-project-id/app/__generated__/_index.tsx b/fixtures/ssg-netlify-by-project-id/app/__generated__/_index.tsx
new file mode 100644
index 0000000000..358ed16bc9
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/app/__generated__/_index.tsx
@@ -0,0 +1,33 @@
+/* eslint-disable */
+/* This is a auto generated file for building the project */
+
+import { Fragment, useState } from "react";
+import type { FontAsset, ImageAsset } from "@webstudio-is/sdk";
+import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ Body as Body,
+ Heading as Heading,
+} from "@webstudio-is/sdk-components-react";
+
+export const siteName = undefined;
+
+export const favIconAsset: ImageAsset | undefined = undefined;
+
+// Font assets on current page (can be preloaded)
+export const pageFontAssets: FontAsset[] = [];
+
+export const pageBackgroundImageAssets: ImageAsset[] = [];
+
+export const CustomCode = () => {
+ return <></>;
+};
+
+const Page = ({}: { system: any }) => {
+ return (
+ <Body className="w-body">
+ <Heading className="w-heading">{"FIXTURE-CLIENT-DO-NOT-TOUCH"}</Heading>
+ </Body>
+ );
+};
+
+export { Page };
diff --git a/fixtures/ssg-netlify-by-project-id/app/__generated__/index.css b/fixtures/ssg-netlify-by-project-id/app/__generated__/index.css
new file mode 100644
index 0000000000..25474bc937
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/app/__generated__/index.css
@@ -0,0 +1,68 @@
+html {
+ margin: 0;
+ display: grid;
+ min-height: 100%;
+}
+@media all {
+ :where(body.w-body) {
+ font-family: Arial, Roboto, sans-serif;
+ font-size: 16px;
+ line-height: 1.2;
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+ margin: 0;
+ }
+ :where(h1.w-heading) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ :where(h2.w-heading) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ :where(h3.w-heading) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ :where(h4.w-heading) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ :where(h5.w-heading) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+ :where(h6.w-heading) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ }
+}
diff --git a/fixtures/ssg-netlify-by-project-id/app/constants.mjs b/fixtures/ssg-netlify-by-project-id/app/constants.mjs
new file mode 100644
index 0000000000..a3e96aa259
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/app/constants.mjs
@@ -0,0 +1,33 @@
+/**
+ * We use mjs extension as constants in this file is shared with the build script
+ * and we use `node --eval` to extract the constants.
+ */
+export const assetBaseUrl = "/assets/";
+export const imageBaseUrl = "/assets/";
+
+/**
+ * @type {import("@webstudio-is/image").ImageLoader}
+ */
+export const imageLoader = (props) => {
+ if (URL.canParse(props.src)) {
+ return props.src;
+ }
+
+ if (process.env.NODE_ENV !== "production") {
+ return imageBaseUrl + props.src;
+ }
+
+ if (props.format === "raw") {
+ return imageBaseUrl + props.src;
+ }
+
+ // https://docs.netlify.com/image-cdn/overview/
+ return (
+ "/.netlify/images?url=" +
+ encodeURIComponent(imageBaseUrl + props.src) +
+ "&w=" +
+ props.width +
+ "&q=" +
+ props.quality
+ );
+};
diff --git a/fixtures/ssg-netlify-by-project-id/package.json b/fixtures/ssg-netlify-by-project-id/package.json
new file mode 100644
index 0000000000..11da69a234
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/package.json
@@ -0,0 +1,44 @@
+{
+ "name": "ssg-netlify-by-project-id",
+ "version": "1.0.0",
+ "description": "",
+ "scripts": {
+ "build": "vite build",
+ "postbuild": "prettier --write \"dist/**/*.html\" || true",
+ "dev": "vite dev",
+ "typecheck": "tsc",
+ "cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio",
+ "fixtures:link": "pnpm cli link --link https://p-8a7358b1-7de3-459d-b7b1-56dddfb6ce1e-dot-${BUILDER_HOST:-main.development.webstudio.is}'?authToken=f55154e6-36b9-4920-bc81-3095cc88f8ff'",
+ "fixtures:sync": "pnpm cli sync && pnpm prettier --write ./.webstudio/",
+ "fixtures:build": "rm -rf pages && pnpm cli build --template ssg-netlify --template internal --preview && prettier --write ."
+ },
+ "engines": {
+ "node": ">=20.0.0"
+ },
+ "type": "module",
+ "keywords": [],
+ "author": "",
+ "license": "ISC",
+ "private": true,
+ "sideEffects": false,
+ "devDependencies": {
+ "@types/react": "^18.2.70",
+ "@types/react-dom": "^18.2.25",
+ "@vitejs/plugin-react": "^4.3.1",
+ "prettier": "3.3.3",
+ "typescript": "5.5.2",
+ "vite": "^5.4.0",
+ "webstudio": "workspace:*"
+ },
+ "dependencies": {
+ "@webstudio-is/image": "workspace:*",
+ "@webstudio-is/react-sdk": "workspace:*",
+ "@webstudio-is/sdk": "workspace:*",
+ "@webstudio-is/sdk-components-react": "workspace:*",
+ "@webstudio-is/sdk-components-react-radix": "workspace:*",
+ "@webstudio-is/sdk-components-react-remix": "workspace:*",
+ "react": "18.3.0-canary-14898b6a9-20240318",
+ "react-dom": "18.3.0-canary-14898b6a9-20240318",
+ "vike": "^0.4.182"
+ }
+}
diff --git a/fixtures/ssg-netlify-by-project-id/pages/+config.ts b/fixtures/ssg-netlify-by-project-id/pages/+config.ts
new file mode 100644
index 0000000000..537824865d
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/pages/+config.ts
@@ -0,0 +1,12 @@
+import type { Config } from "vike/types";
+
+export default {
+ meta: {
+ Head: {
+ env: { server: true, client: true },
+ },
+ lang: {
+ env: { server: true, client: true },
+ },
+ },
+} satisfies Config;
diff --git a/fixtures/ssg-netlify-by-project-id/pages/index/+Head.tsx b/fixtures/ssg-netlify-by-project-id/pages/index/+Head.tsx
new file mode 100644
index 0000000000..4f59a43abe
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/pages/index/+Head.tsx
@@ -0,0 +1,92 @@
+import type { PageContext } from "vike/types";
+import { assetBaseUrl, imageLoader } from "../../app/constants.mjs";
+import {
+ favIconAsset,
+ pageBackgroundImageAssets,
+ pageFontAssets,
+ siteName,
+} from "../../app/__generated__/_index";
+import "../../app/__generated__/index.css";
+
+export const Head = ({ data }: { data: PageContext["data"] }) => {
+ const { pageMeta } = data;
+ const { origin } = new URL(data.url);
+ const ldJson = {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ name: siteName,
+ url: origin,
+ };
+ let socialImageUrl = pageMeta.socialImageUrl;
+ if (pageMeta.socialImageAssetName) {
+ socialImageUrl = `${origin}${imageLoader({
+ src: pageMeta.socialImageAssetName,
+ // Do not transform social image (not enough information do we need to do this)
+ format: "raw",
+ })}`;
+ }
+ return (
+ <>
+ {data.url && <meta property="og:url" content={data.url} />}
+ <title>{pageMeta.title}</title>
+ <meta property="og:title" content={pageMeta.title} />
+ {pageMeta.description && (
+ <>
+ <meta name="description" content={pageMeta.description} />
+ <meta property="og:description" content={pageMeta.description} />
+ </>
+ )}
+ <meta property="og:type" content="website" />
+ {siteName && <meta property="og:site_name" content={siteName} />}
+ {socialImageUrl && (
+ <meta property="og:image" content={pageMeta.socialImageUrl} />
+ )}
+ {siteName && (
+ <script
+ type="application/ld+json"
+ dangerouslySetInnerHTML={{
+ __html: JSON.stringify(ldJson, null, 2),
+ }}
+ ></script>
+ )}
+ {pageMeta.excludePageFromSearch && (
+ <meta name="robots" content="noindex, nofollow" />
+ )}
+ {pageMeta.custom.map(({ property, content }) => (
+ <meta key={property} property={property} content={content} />
+ ))}
+
+ {favIconAsset && (
+ <link
+ rel="icon"
+ href={imageLoader({
+ src: favIconAsset.name,
+ // width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
+ width: 144,
+ height: 144,
+ fit: "pad",
+ quality: 100,
+ format: "auto",
+ })}
+ />
+ )}
+ {pageFontAssets.map((asset) => (
+ <link
+ key={asset.id}
+ rel="preload"
+ href={`${assetBaseUrl}${asset.name}`}
+ as="font"
+ crossOrigin="anonymous"
+ />
+ ))}
+ {pageBackgroundImageAssets.map((asset) => (
+ <link
+ key={asset.id}
+ rel="preload"
+ href={`${assetBaseUrl}${asset.name}`}
+ as="image"
+ />
+ ))}
+ </>
+ );
+};
diff --git a/fixtures/ssg-netlify-by-project-id/pages/index/+Page.tsx b/fixtures/ssg-netlify-by-project-id/pages/index/+Page.tsx
new file mode 100644
index 0000000000..fed8c20a11
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/pages/index/+Page.tsx
@@ -0,0 +1,26 @@
+import type { PageContext } from "vike/types";
+import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime";
+import {
+ assetBaseUrl,
+ imageBaseUrl,
+ imageLoader,
+} from "../../app/constants.mjs";
+import { Page } from "../../app/__generated__/_index";
+
+const PageComponent = ({ data }: { data: PageContext["data"] }) => {
+ const { system, resources, url } = data;
+ return (
+ <ReactSdkContext.Provider
+ value={{
+ imageLoader,
+ assetBaseUrl,
+ imageBaseUrl,
+ resources,
+ }}
+ >
+ {/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}
+ <Page key={url} system={system} />
+ </ReactSdkContext.Provider>
+ );
+};
+export default PageComponent;
diff --git a/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts b/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts
new file mode 100644
index 0000000000..c6c77c36bb
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts
@@ -0,0 +1,40 @@
+import type { PageContextServer } from "vike/types";
+import { redirect } from "vike/abort";
+import { loadResources } from "@webstudio-is/sdk";
+import {
+ getPageMeta,
+ getResources,
+} from "../../app/__generated__/_index.server";
+
+export const data = async (pageContext: PageContextServer) => {
+ const url = new URL(pageContext.urlOriginal, "http://url");
+ const headers = new Headers(pageContext.headers ?? {});
+ const host = headers.get("x-forwarded-host") || headers.get("host") || "";
+ url.host = host;
+ url.protocol = "https";
+
+ const params = pageContext.routeParams;
+ const system = {
+ params,
+ search: Object.fromEntries(url.searchParams),
+ origin: url.origin,
+ };
+
+ const resources = await loadResources(fetch, getResources({ system }).data);
+ const pageMeta = getPageMeta({ system, resources });
+
+ if (pageMeta.redirect) {
+ const status =
+ pageMeta.status === 301 || pageMeta.status === 302
+ ? pageMeta.status
+ : 302;
+ throw redirect(pageMeta.redirect, status);
+ }
+
+ return {
+ url: url.href,
+ system,
+ resources,
+ pageMeta,
+ } satisfies PageContextServer["data"];
+};
diff --git a/fixtures/ssg-netlify-by-project-id/renderer/+onRenderClient.tsx b/fixtures/ssg-netlify-by-project-id/renderer/+onRenderClient.tsx
new file mode 100644
index 0000000000..fb75527ca5
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/renderer/+onRenderClient.tsx
@@ -0,0 +1,30 @@
+import { type Root, createRoot } from "react-dom/client";
+import type { OnRenderClientSync } from "vike/types";
+// @todo think about how to make __generated__ typeable
+/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
+// @ts-ignore
+import { CustomCode } from "../app/__generated__/_index";
+
+let root: Root;
+
+export const onRenderClient: OnRenderClientSync = (pageContext) => {
+ const lang = pageContext.data.pageMeta.language || "en";
+ const Head = pageContext.config.Head ?? (() => <></>);
+ const Page = pageContext.Page ?? (() => <></>);
+ const htmlContent = (
+ <>
+ <head>
+ <meta charSet="UTF-8" />
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
+ <Head data={pageContext.data} />
+ <CustomCode />
+ </head>
+ <Page data={pageContext.data} />
+ </>
+ );
+ if (root === undefined) {
+ root = createRoot(document.documentElement);
+ }
+ document.documentElement.lang = lang;
+ root.render(htmlContent);
+};
diff --git a/fixtures/ssg-netlify-by-project-id/renderer/+onRenderHtml.tsx b/fixtures/ssg-netlify-by-project-id/renderer/+onRenderHtml.tsx
new file mode 100644
index 0000000000..2afbd909d8
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/renderer/+onRenderHtml.tsx
@@ -0,0 +1,29 @@
+import { renderToString } from "react-dom/server";
+import { dangerouslySkipEscape, escapeInject } from "vike/server";
+import type { OnRenderHtmlSync } from "vike/types";
+// @todo think about how to make __generated__ typeable
+/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
+// @ts-ignore
+import { CustomCode } from "../app/__generated__/_index";
+
+export const onRenderHtml: OnRenderHtmlSync = (pageContext) => {
+ const lang = pageContext.data.pageMeta.language || "en";
+ const Head = pageContext.config.Head ?? (() => <></>);
+ const Page = pageContext.Page ?? (() => <></>);
+ const html = dangerouslySkipEscape(
+ renderToString(
+ <html lang={lang}>
+ <head>
+ <meta charSet="UTF-8" />
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
+ <Head data={pageContext.data} />
+ <CustomCode />
+ </head>
+ <Page data={pageContext.data} />
+ </html>
+ )
+ );
+ return escapeInject`<!DOCTYPE html>
+${html}
+`;
+};
diff --git a/fixtures/ssg-netlify-by-project-id/tsconfig.json b/fixtures/ssg-netlify-by-project-id/tsconfig.json
new file mode 100644
index 0000000000..834b51c62d
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/tsconfig.json
@@ -0,0 +1,23 @@
+{
+ "include": ["**/*.ts", "**/*.tsx", "**/*.mjs"],
+ "compilerOptions": {
+ "lib": ["DOM", "DOM.Iterable", "ESNext"],
+ "types": [
+ "vite/client",
+ "@webstudio-is/react-sdk/placeholder",
+ "./vike.d.ts"
+ ],
+ "isolatedModules": true,
+ "esModuleInterop": true,
+ "jsx": "react-jsx",
+ "module": "ESNext",
+ "moduleResolution": "bundler",
+ "target": "ES2022",
+ "strict": true,
+ "allowJs": true,
+ "forceConsistentCasingInFileNames": true,
+ "noEmit": true,
+ "skipLibCheck": true,
+ "customConditions": ["webstudio"]
+ }
+}
diff --git a/fixtures/ssg-netlify-by-project-id/vike.d.ts b/fixtures/ssg-netlify-by-project-id/vike.d.ts
new file mode 100644
index 0000000000..3c77162037
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/vike.d.ts
@@ -0,0 +1,26 @@
+import type { ImageLoader } from "@webstudio-is/image";
+import type { PageMeta, System } from "@webstudio-is/sdk";
+
+declare global {
+ namespace Vike {
+ interface Config {
+ lang?: (props: { data: PageData }) => string;
+ Head?: (props: { data: PageData }) => React.ReactNode;
+ }
+
+ interface PageContext {
+ constants: {
+ assetBaseUrl: string;
+ imageBaseUrl: string;
+ imageLoader: ImageLoader;
+ };
+ data: {
+ url: string;
+ system: System;
+ resources: Record<string, unknown>;
+ pageMeta: PageMeta;
+ };
+ Page?: (props: { data: PageData }) => React.ReactNode;
+ }
+ }
+}
diff --git a/fixtures/ssg-netlify-by-project-id/vite.config.ts b/fixtures/ssg-netlify-by-project-id/vite.config.ts
new file mode 100644
index 0000000000..d219c4d8b9
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/vite.config.ts
@@ -0,0 +1,7 @@
+import { defineConfig } from "vite";
+import react from "@vitejs/plugin-react";
+import vike from "vike/plugin";
+
+export default defineConfig({
+ plugins: [react(), vike({ prerender: true })],
+});
diff --git a/packages/http-client/src/index.ts b/packages/http-client/src/index.ts
index 6507e626ec..d2bbce3248 100644
--- a/packages/http-client/src/index.ts
+++ b/packages/http-client/src/index.ts
@@ -37,24 +37,20 @@ export type Data = {
assets: Array<Asset>;
};
-export const loadProjectDataByProjectId = async (params: {
+// @todo: broken as expects non 200 code
+const getLatestBuildUsingProjectId = async (params: {
projectId: string;
origin: string;
- authToken?: string;
-}): Promise<Data> => {
- const result = await getLatestBuildUsingProjectId(params);
- if (result.buildId === null) {
- throw new Error(`The project is not published yet`);
- }
-
- const url = new URL(params.origin);
- url.pathname = `/rest/build/${result.buildId}`;
+ authToken: string;
+}): Promise<{ buildId: string | null }> => {
+ const { origin, projectId, authToken } = params;
+ const url = new URL(origin);
+ url.pathname = `/rest/buildId/${projectId}`;
- if (params.authToken) {
- url.searchParams.append("authToken", params.authToken);
- }
+ const headers = new Headers();
+ headers.set("x-auth-token", authToken);
- const response = await fetch(url.href);
+ const response = await fetch(url.href, { headers });
if (response.ok) {
return await response.json();
@@ -78,11 +74,11 @@ export const loadProjectDataByBuildId = async (
const url = new URL(params.origin);
url.pathname = `/rest/build/${params.buildId}`;
- const headers: Record<string, string> = {};
+ const headers = new Headers();
if ("seviceToken" in params) {
- headers.Authorization = params.seviceToken;
+ headers.set("Authorization", params.seviceToken);
} else {
- headers["x-auth-token"] = params.authToken;
+ headers.set("x-auth-token", params.authToken);
}
const response = await fetch(url.href, {
@@ -97,27 +93,21 @@ export const loadProjectDataByBuildId = async (
throw new Error(message.slice(0, 1000));
};
-// @todo: broken as expects non 200 code
-export const getLatestBuildUsingProjectId = async (params: {
+export const loadProjectDataByProjectId = async (params: {
projectId: string;
origin: string;
- authToken?: string;
-}): Promise<{ buildId: string | null }> => {
- const { origin, projectId, authToken } = params;
- const url = new URL(origin);
- url.pathname = `/rest/buildId/${projectId}`;
-
- if (authToken) {
- url.searchParams.append("authToken", authToken);
- }
- const response = await fetch(url.href);
-
- if (response.ok) {
- return await response.json();
+ authToken: string;
+}): Promise<Data> => {
+ const result = await getLatestBuildUsingProjectId(params);
+ if (result.buildId === null) {
+ throw new Error(`The project is not published yet`);
}
- const message = await response.text();
- throw new Error(message.slice(0, 1000));
+ return await loadProjectDataByBuildId({
+ buildId: result.buildId,
+ origin: params.origin,
+ authToken: params.authToken,
+ });
};
// For easier detecting the builder URL
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 4090e86bd9..3c2845a059 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -541,6 +541,58 @@ importers:
specifier: workspace:*
version: link:../../packages/cli
+ fixtures/ssg-netlify-by-project-id:
+ dependencies:
+ '@webstudio-is/image':
+ specifier: workspace:*
+ version: link:../../packages/image
+ '@webstudio-is/react-sdk':
+ specifier: workspace:*
+ version: link:../../packages/react-sdk
+ '@webstudio-is/sdk':
+ specifier: workspace:*
+ version: link:../../packages/sdk
+ '@webstudio-is/sdk-components-react':
+ specifier: workspace:*
+ version: link:../../packages/sdk-components-react
+ '@webstudio-is/sdk-components-react-radix':
+ specifier: workspace:*
+ version: link:../../packages/sdk-components-react-radix
+ '@webstudio-is/sdk-components-react-remix':
+ specifier: workspace:*
+ version: link:../../packages/sdk-components-react-remix
+ react:
+ specifier: 18.3.0-canary-14898b6a9-20240318
+ version: 18.3.0-canary-14898b6a9-20240318
+ react-dom:
+ specifier: 18.3.0-canary-14898b6a9-20240318
+ version: 18.3.0-canary-14898b6a9-20240318([email protected])
+ vike:
+ specifier: ^0.4.182
+ devDependencies:
+ '@types/react':
+ specifier: ^18.2.70
+ version: 18.2.79
+ '@types/react-dom':
+ specifier: ^18.2.25
+ version: 18.2.25
+ '@vitejs/plugin-react':
+ specifier: ^4.3.1
+ version: 4.3.1([email protected](@types/[email protected]))
+ prettier:
+ specifier: 3.3.3
+ version: 3.3.3
+ typescript:
+ specifier: 5.5.2
+ version: 5.5.2
+ vite:
+ specifier: ^5.4.0
+ version: 5.4.0(@types/[email protected])
+ webstudio:
+ specifier: workspace:*
+ version: link:../../packages/cli
+
fixtures/webstudio-cloudflare-template:
dependencies:
'@remix-run/cloudflare':
@@ -10019,7 +10071,7 @@ snapshots:
'@babel/traverse': 7.24.5
'@babel/types': 7.24.7
convert-source-map: 2.0.0
- debug: 4.3.4
+ debug: 4.3.6
gensync: 1.0.0-beta.2
json5: 2.2.3
semver: 6.3.1