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.

Drop css endpoint (#1656)

Bogdan Chadkin25c1fb3706e1
diff --git a/apps/builder/app/canvas/shared/styles.ts b/apps/builder/app/canvas/shared/styles.ts
index 1818a8414d..4004246795 100644
--- a/apps/builder/app/canvas/shared/styles.ts
+++ b/apps/builder/app/canvas/shared/styles.ts
@@ -54,7 +54,7 @@ const presetStylesEngine = createCssEngine({ name: "preset-styles" });
// If user sets `height: 100px` or does anything that would give it a height - we remove the helper padding right away, so user can actually see the height they set
//
// In other words we prevent elements from collapsing when they have 0 height or width by making them non-zero on canvas, but then we remove those paddings as soon as element doesn't collapse.
-export const helperStyles = [
+const helperStyles = [
// When double clicking into an element to edit text, it should not select the word.
`[${idAttribute}] {
user-select: none;
diff --git a/apps/builder/app/routes/s.css.ts b/apps/builder/app/routes/s.css.ts
deleted file mode 100644
index d88448e000..0000000000
--- a/apps/builder/app/routes/s.css.ts
+++ /dev/null
@@ -1,83 +0,0 @@
-import { type ActionArgs, json } from "@remix-run/node";
-import { generateCssText } from "@webstudio-is/react-sdk";
-import { db } from "@webstudio-is/project/index.server";
-import { createCssEngine } from "@webstudio-is/css-engine";
-import env from "~/env/env.public.server";
-import { getBuildParams } from "~/shared/router-utils";
-import { sentryException } from "~/shared/sentry";
-import { createContext } from "~/shared/context.server";
-import { loadCanvasData } from "~/shared/db";
-import { helperStyles } from "~/canvas/shared/styles";
-
-export const loader = async ({ request }: ActionArgs) => {
- try {
- const buildParams = getBuildParams(request);
-
- const context = await createContext(request, "dev");
-
- if (buildParams === undefined) {
- throw json("Required project info", { status: 400 });
- }
-
- const project = await db.project.loadByParams(buildParams, context);
-
- if (project === null) {
- throw json("Project not found", { status: 404 });
- }
-
- const canvasData = await loadCanvasData(
- {
- project,
- env: "dev",
- pageIdOrPath:
- "pageId" in buildParams ? buildParams.pageId : buildParams.pagePath,
- },
- context
- );
-
- if (canvasData === undefined) {
- throw json("Page not found", { status: 404 });
- }
-
- const cssText = generateCssText(
- {
- assets: canvasData.assets,
- breakpoints: canvasData.build?.breakpoints,
- styles: canvasData.build?.styles,
- styleSourceSelections: canvasData.build?.styleSourceSelections,
- },
- {
- assetBaseUrl: env.ASSET_BASE_URL,
- }
- );
-
- const engine = createCssEngine({ name: "ssr" });
- for (const style of helperStyles) {
- engine.addPlaintextRule(style);
- }
-
- return new Response(`${cssText}\n${engine.cssText}`, {
- headers: {
- "Content-Type": "text/css",
- // We have no way with Remix links to know if CSS has changed (no ?cache-breaker in url)
- // We can add Last-Modified and change Cache-Control: no-cache, but this is only used to publish on localhost.
- // And can be completely omitted for Designer Canvas see https://github.com/webstudio-is/webstudio-builder/issues/1044
- // This is not a problem on the published site, since we know the data at build time.
- // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
- "Cache-Control": "no-store",
- },
- });
- } catch (error) {
- // If a Response is thrown, we're rethrowing it for Remix to handle.
- // https://remix.run/docs/en/v1/api/conventions#throwing-responses-in-loaders
- if (error instanceof Response) {
- throw error;
- }
-
- sentryException({ error });
- return {
- errors: error instanceof Error ? error.message : String(error),
- env,
- };
- }
-};
diff --git a/apps/builder/app/shared/context.server.ts b/apps/builder/app/shared/context.server.ts
index 9439bf1ef6..993f73a8de 100644
--- a/apps/builder/app/shared/context.server.ts
+++ b/apps/builder/app/shared/context.server.ts
@@ -6,16 +6,7 @@ const createAuthorizationContext = async (
request: Request,
buildEnv: AppContext["authorization"]["buildEnv"]
): Promise<AppContext["authorization"]> => {
- const originUrl = new URL(request.url);
- let url = originUrl;
-
- // In case of css use referrer as url to extract tokens from canvas iframe href
- if (originUrl.pathname === "/s/css") {
- const referer = request.headers.get("referer");
- if (referer !== null) {
- url = new URL(referer);
- }
- }
+ const url = new URL(request.url);
const authToken = url.searchParams.get("authToken") ?? url.hostname;
diff --git a/apps/builder/app/shared/db/canvas.server.ts b/apps/builder/app/shared/db/canvas.server.ts
index e180c636a0..c675ad4508 100644
--- a/apps/builder/app/shared/db/canvas.server.ts
+++ b/apps/builder/app/shared/db/canvas.server.ts
@@ -55,7 +55,7 @@ export const loadProductionCanvasData = async (
};
};
-export const loadCanvasData = async (
+const loadCanvasData = async (
props: {
project: Project;
env: "dev" | "prod";
diff --git a/apps/builder/app/shared/router-utils/build-params.ts b/apps/builder/app/shared/router-utils/build-params.ts
index 313f8f5f91..fc52c2a0a2 100644
--- a/apps/builder/app/shared/router-utils/build-params.ts
+++ b/apps/builder/app/shared/router-utils/build-params.ts
@@ -79,24 +79,6 @@ export const getBuildParams = (
): BuildParams | undefined => {
const url = new URL(request.url);
- // Having that we use Remix `export const links` and have no way to pass
- // projectId and other params here, we need to get them from referer.
- if (url.pathname === "/s/css") {
- const referer = request.headers.get("referer");
- if (referer !== null) {
- // Try to get projectId from referrer
- const refererUrl = new URL(referer);
- const projectId = refererUrl.searchParams.get("projectId");
- const pageId = url.searchParams.get("pageId") ?? undefined;
-
- if (projectId !== null) {
- return pageId === undefined
- ? { projectId, pagePath: refererUrl.pathname }
- : { projectId, pageId };
- }
- }
- }
-
const requestHost = getRequestHost(request);
const buildHost = new URL(getBuildOrigin(request, env)).host;
const pageId = url.searchParams.get("pageId") ?? undefined;