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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
feat: add rest api for /s/css
Andras Bacsai76a89f58bd4f
diff --git a/apps/designer/app/routes/rest/css.$projectId.$pageId.tsx b/apps/designer/app/routes/rest/css.$projectId.$pageId.tsxindex 5bddf23b86..977f4b56ee 100644--- a/apps/designer/app/routes/rest/css.$projectId.$pageId.tsx+++ b/apps/designer/app/routes/rest/css.$projectId.$pageId.tsx@@ -1,18 +1,15 @@import { ActionFunction, json } from "@remix-run/node";import { db } from "@webstudio-is/project/server";-import { utils } from "@webstudio-is/project";-import { loadCanvasData } from "~/shared/db";import env from "~/env.server";import { sentryException } from "~/shared/sentry";-import { createCssEngine } from "@webstudio-is/css-engine";-import { idAttribute } from "@webstudio-is/react-sdk";-import { addGlobalRules } from "~/canvas/shared/styles";+import { generateCssText } from "~/shared/css-utils";+import { BuildParams } from "~/shared/router-utils";-export const loader: ActionFunction = async ({ params }) => {+export const loader: ActionFunction = async ({ request, params }) => {try {const projectId = params.projectId ?? undefined;const pageId = params.pageId ?? undefined;- console.log({ projectId, pageId });+if (projectId === undefined) {throw json("Required project id", { status: 404 });}@@ -20,32 +17,14 @@ export const loader: ActionFunction = async ({ params }) => {if (pageId === undefined) {throw json("Required page id", { status: 404 });}-- const project = await db.project.loadByParams({ projectId });-- if (project === null) {- throw json("Project not found", { status: 404 });- }-- const canvasData = await loadCanvasData(project, "prod", pageId);-- if (canvasData === undefined) {- throw json("Page not found", { status: 404 });- }-- const engine = createCssEngine();-- addGlobalRules(engine, canvasData);-- for (const breakpoint of canvasData.breakpoints) {- engine.addMediaRule(breakpoint.id, breakpoint);- }-- const cssRules = utils.tree.getCssRules(canvasData.tree?.root);- for (const [instanceId, cssRule] of cssRules) {- engine.addStyleRule(`[${idAttribute}="${instanceId}"]`, cssRule);- }- const { cssText } = engine;+ const url = new URL(request.url);+ const buildParams: BuildParams = {+ projectId,+ mode: "published",+ pathname: url.pathname,+ pageId,+ };+ const cssText = await generateCssText(buildParams);return new Response(cssText, {headers: {