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
Add reusable functions for routes paths (#419)
Roman Pominov411aa1666c69
diff --git a/apps/designer/app/auth/login.tsx b/apps/designer/app/auth/login.tsxindex 9453ee5d47..6e1bee7ac1 100644--- a/apps/designer/app/auth/login.tsx+++ b/apps/designer/app/auth/login.tsx@@ -13,6 +13,7 @@ import interStyles from "~/shared/font-faces/inter.css";import { GithubIcon, CommitIcon, GoogleIcon } from "@webstudio-is/icons";import { LoginButton } from "./components/login-button";import loginStyles from "./login.css";+import { authPath } from "~/shared/router-utils";export const links: LinksFunction = () => {return [@@ -52,7 +53,7 @@ export const Login = ({ errorMessage }: { errorMessage: string }) => {</Text>) : null}<Flex gap="2" direction="column">- <Form action="/auth/github" method="post">+ <Form action={authPath({ provider: "github" })} method="post"><LoginButton enabled={data.isGithubEnabled}><Flex gap="2" align="center"><Flex css={{ width: 20, height: 20 }}>@@ -62,7 +63,7 @@ export const Login = ({ errorMessage }: { errorMessage: string }) => {</Flex></LoginButton></Form>- <Form action="/auth/google" method="post">+ <Form action={authPath({ provider: "google" })} method="post"><LoginButton enabled={data.isGoogleEnabled}><Flex gap="2" align="center"><Flex css={{ width: 20, height: 20 }}>@@ -76,7 +77,7 @@ export const Login = ({ errorMessage }: { errorMessage: string }) => {(isDevLoginOpen ? (<Flexas="form"- action="/auth/dev"+ action={authPath({ provider: "dev" })}method="post"css={{flexDirection: "row",diff --git a/apps/designer/app/canvas/shared/sync/use-sync.ts b/apps/designer/app/canvas/shared/sync/use-sync.tsindex 96c5734760..c25cd4bb04 100644--- a/apps/designer/app/canvas/shared/sync/use-sync.ts+++ b/apps/designer/app/canvas/shared/sync/use-sync.ts@@ -3,6 +3,7 @@ import { sync } from "immerhin";import { enqueue } from "./queue";import type { Build } from "@webstudio-is/project";import { Tree } from "@webstudio-is/react-sdk";+import { restPatchPath } from "~/shared/router-utils";export const useSync = ({treeId,@@ -20,7 +21,7 @@ export const useSync = ({// and backend fetches and updates big objects, so if we send quickly,// we end up overwriting thingsenqueue(() =>- fetch(`/rest/patch`, {+ fetch(restPatchPath(), {method: "post",body: JSON.stringify({transactions: entries,diff --git a/apps/designer/app/config.ts b/apps/designer/app/config.tsdeleted file mode 100644index 7bcd5c7519..0000000000--- a/apps/designer/app/config.ts+++ /dev/null@@ -1,11 +0,0 @@-const config = {- designerPath: "/designer",- dashboardPath: "/dashboard",- loginPath: "/login",- logoutPath: "/logout",- googleCallbackPath: "/google/callback",- githubCallbackPath: "/github/callback",- authPath: "/auth",-};-export default config;-export type Config = typeof config;diff --git a/apps/designer/app/dashboard/components/card.tsx b/apps/designer/app/dashboard/components/card.tsxindex 9f41c825c2..ec695aba62 100644--- a/apps/designer/app/dashboard/components/card.tsx+++ b/apps/designer/app/dashboard/components/card.tsx@@ -10,16 +10,15 @@ import {Heading,Text,} from "@webstudio-is/design-system";+import { designerPath } from "~/shared/router-utils";type SelectProjectProjectCardProps = {projects: Array<{ id: string; title: string }>;- config: { designerPath: string };errors: string;};export const SelectProjectCard = ({projects,- config,errors,}: SelectProjectProjectCardProps) => {const [selectedProject, setSelectedProject] = useState("");@@ -28,7 +27,7 @@ export const SelectProjectCard = ({const transition = useTransition();const handleOpen = () => {- navigate(`${config.designerPath}/${selectedProject}`);+ navigate(designerPath({ projectId: selectedProject }));};const options = ["", ...projects.map((project) => project.id)];diff --git a/apps/designer/app/dashboard/components/header.tsx b/apps/designer/app/dashboard/components/header.tsxindex 379c29bdc6..fd8020561b 100644--- a/apps/designer/app/dashboard/components/header.tsx+++ b/apps/designer/app/dashboard/components/header.tsx@@ -11,6 +11,7 @@ import {} from "@webstudio-is/design-system";import { User } from "@webstudio-is/prisma-client";import { useNavigate } from "react-router-dom";+import { logoutPath } from "~/shared/router-utils";export const DashboardHeader = ({ user }: { user: User }) => {const navigate = useNavigate();@@ -44,7 +45,7 @@ export const DashboardHeader = ({ user }: { user: User }) => {</Button></DropdownMenuTrigger><DropdownMenuContent>- <DropdownMenuItem onSelect={() => navigate("/logout")}>+ <DropdownMenuItem onSelect={() => navigate(logoutPath())}><Text>Logout</Text></DropdownMenuItem></DropdownMenuContent>diff --git a/apps/designer/app/dashboard/dashboard.tsx b/apps/designer/app/dashboard/dashboard.tsxindex 0848e102d9..e96d6c9c36 100644--- a/apps/designer/app/dashboard/dashboard.tsx+++ b/apps/designer/app/dashboard/dashboard.tsx@@ -22,10 +22,9 @@ export const links = () => {type DashboardProps = {projects?: Array<{ id: string; title: string }>;user: User;- config: { designerPath: string };};-export const Dashboard = ({ projects = [], config, user }: DashboardProps) => {+export const Dashboard = ({ projects = [], user }: DashboardProps) => {const actionData = useActionData();return (<>@@ -36,11 +35,7 @@ export const Dashboard = ({ projects = [], config, user }: DashboardProps) => {align="center"justify="center">- <SelectProjectCard- projects={projects}- config={config}- errors={actionData?.errors}- />+ <SelectProjectCard projects={projects} errors={actionData?.errors} /></Flex></>);diff --git a/apps/designer/app/designer/designer.tsx b/apps/designer/app/designer/designer.tsxindex bc2dd92f88..d39d3e6556 100644--- a/apps/designer/app/designer/designer.tsx+++ b/apps/designer/app/designer/designer.tsx@@ -5,7 +5,6 @@ import {type Project,utils as projectUtils,} from "@webstudio-is/project";-import type { Config } from "~/config";import { Box, type CSS, Flex, Grid } from "@webstudio-is/design-system";import interStyles from "~/shared/font-faces/inter.css";import { SidebarLeft } from "./features/sidebar-left";@@ -40,8 +39,8 @@ import {import { useClientSettings } from "./shared/client-settings";import { Navigator } from "./features/sidebar-left";import { PANEL_WIDTH } from "./shared/constants";-import env from "~/shared/env";import { useSetAssets } from "./shared/assets";+import { getBuildUrl } from "~/shared/router-utils";export const links = () => {return [@@ -246,7 +245,6 @@ const NavigatorPanel = ({ publish, isPreviewMode }: NavigatorPanelProps) => {};export type DesignerProps = {- config: Config;project: Project;pages: Pages;pageId: string;@@ -254,7 +252,6 @@ export type DesignerProps = {};export const Designer = ({- config,project,pages,pageId,@@ -294,25 +291,19 @@ export const Designer = ({return page;}, [pages, pageId]);- const buildUrl = new URL(buildOrigin);- buildUrl.pathname = page.path;- if (env.BUILD_REQUIRE_SUBDOMAIN) {- buildUrl.host = `${project.domain}.${buildUrl.host}`;- } else {- buildUrl.searchParams.set("projectId", project.id);- }-- buildUrl.searchParams.set("mode", "edit");- const canvasUrl = buildUrl.toString();+ const canvasUrl = getBuildUrl({ buildOrigin, project, page, mode: "edit" });- buildUrl.searchParams.set("mode", "preview");- const previewUrl = buildUrl.toString();+ const previewUrl = getBuildUrl({+ buildOrigin,+ project,+ page,+ mode: "preview",+ });return (<ChromeWrapper isPreviewMode={isPreviewMode}><Topbarcss={{ gridArea: "header" }}- config={config}project={project}publish={publish}previewUrl={previewUrl}@@ -336,7 +327,7 @@ export const Designer = ({</Workspace></Main><SidePanel gridArea="sidebar" isPreviewMode={isPreviewMode}>- <SidebarLeft publish={publish} config={config} />+ <SidebarLeft publish={publish} /></SidePanel><NavigatorPanel publish={publish} isPreviewMode={isPreviewMode} /><SidePaneldiff --git a/apps/designer/app/designer/features/sidebar-left/panels/pages/pages.tsx b/apps/designer/app/designer/features/sidebar-left/panels/pages/pages.tsxindex 4ed5be2d14..e3c2b9e8e6 100644--- a/apps/designer/app/designer/features/sidebar-left/panels/pages/pages.tsx+++ b/apps/designer/app/designer/features/sidebar-left/panels/pages/pages.tsx@@ -19,7 +19,6 @@ import { CloseButton, Header } from "../../lib/header";import { type Page, type Pages } from "@webstudio-is/project";import { useCallback, useMemo, useState } from "react";import { useNavigate } from "react-router-dom";-import { type Config } from "~/config";import {useCurrentPageId,usePages,@@ -27,11 +26,11 @@ import {} from "~/designer/shared/nano-states";import { SettingsPanel } from "./settings-panel";import { NewPageSettings, PageSettings } from "./settings";+import { designerPath } from "~/shared/router-utils";type TabContentProps = {onSetActiveTab: (tabName: TabName) => void;publish: Publish;- config: Config;};type PagesTreeNode =@@ -187,11 +186,12 @@ export const TabContent = (props: TabContentProps) => {if (project === undefined) {return;}- if (pageId === "home") {- navigate(`${props.config.designerPath}/${project.id}`);- } else {- navigate(`${props.config.designerPath}/${project.id}?pageId=${pageId}`);- }+ navigate(+ designerPath({+ projectId: project.id,+ pageId: pageId === "home" ? undefined : pageId,+ })+ );};const newPageId = "new-page";diff --git a/apps/designer/app/designer/features/sidebar-left/panels/pages/settings.tsx b/apps/designer/app/designer/features/sidebar-left/panels/pages/settings.tsxindex 900c0a2036..ec91f817ef 100644--- a/apps/designer/app/designer/features/sidebar-left/panels/pages/settings.tsx+++ b/apps/designer/app/designer/features/sidebar-left/panels/pages/settings.tsx@@ -29,6 +29,7 @@ import type {EditPageData,CreatePageData,} from "~/shared/pages";+import { restPagesPath } from "~/shared/router-utils";const Group = styled(Flex, {marginBottom: "$3",@@ -121,7 +122,7 @@ export const NewPageSettings = ({const handleSubmit = () => {fetcher.submit(values, {method: "put",- action: `/rest/pages/${projectId}`,+ action: restPagesPath({ projectId }),});};@@ -244,7 +245,7 @@ export const PageSettings = ({fetcher.submit(toFormData({ id: pageId, ...valuesToSubmit }), {method: "post",- action: `/rest/pages/${projectId}`,+ action: restPagesPath({ projectId }),});setSubmittedValues(valuesToSubmit);@@ -262,7 +263,7 @@ export const PageSettings = ({// because we don't want the request to be canceled when the component unmountssubmitPersistently<EditPageData>(toFormData({ id: pageId, ...submittedValues, ...unsavedValues }),- { method: "post", action: `/rest/pages/${projectId}` },+ { method: "post", action: restPagesPath({ projectId }) },(data) => {if (data.status === "error") {toastUnknownFieldErrors(normalizeErrors(data.errors), []);@@ -283,7 +284,7 @@ export const PageSettings = ({// because we don't want the request to be canceled when the component unmountssubmitPersistently<DeletePageData>({ id: pageId },- { method: "delete", action: `/rest/pages/${projectId}` },+ { method: "delete", action: restPagesPath({ projectId }) },(data) => {if (data.status === "error") {toastUnknownFieldErrors(normalizeErrors(data.errors), []);diff --git a/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsx b/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsxindex 7be0e00aac..4d567a6151 100644--- a/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsx+++ b/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsx@@ -13,16 +13,14 @@ import { isFeatureEnabled } from "~/shared/feature-flags";import { useClientSettings } from "~/designer/shared/client-settings";import { PANEL_WIDTH } from "~/designer/shared/constants";import { Flex } from "@webstudio-is/design-system";-import { Config } from "~/config";const none = { TabContent: () => null };type SidebarLeftProps = {publish: Publish;- config: Config;};-export const SidebarLeft = ({ publish, config }: SidebarLeftProps) => {+export const SidebarLeft = ({ publish }: SidebarLeftProps) => {const [dragAndDropState] = useDragAndDropState();const [activeTab, setActiveTab] = useState<TabName>("none");const { TabContent } = activeTab === "none" ? none : panels[activeTab];@@ -79,11 +77,7 @@ export const SidebarLeft = ({ publish, config }: SidebarLeftProps) => {: "visible",}}>- <TabContent- publish={publish}- onSetActiveTab={setActiveTab}- config={config}- />+ <TabContent publish={publish} onSetActiveTab={setActiveTab} /></SidebarTabsContent></SidebarTabs></Flex>diff --git a/apps/designer/app/designer/features/topbar/menu/menu.tsx b/apps/designer/app/designer/features/topbar/menu/menu.tsxindex 7833f65652..cc718c5972 100644--- a/apps/designer/app/designer/features/topbar/menu/menu.tsx+++ b/apps/designer/app/designer/features/topbar/menu/menu.tsx@@ -15,7 +15,6 @@ import {Box,} from "@webstudio-is/design-system";import { HamburgerMenuIcon, ChevronRightIcon } from "@webstudio-is/icons";-import type { Config } from "~/config";import { ShortcutHint } from "./shortcut-hint";import {useIsShareDialogOpen,@@ -27,6 +26,7 @@ import {type ThemeSetting,} from "~/shared/theme";import { useClientSettings } from "~/designer/shared/client-settings";+import { dashboardPath } from "~/shared/router-utils";const menuItemCss = {display: "flex",@@ -99,11 +99,10 @@ const ViewMenuItem = () => {};type MenuProps = {- config: Config;publish: Publish;};-export const Menu = ({ config, publish }: MenuProps) => {+export const Menu = ({ publish }: MenuProps) => {const navigate = useNavigate();const [, setIsShareOpen] = useIsShareDialogOpen();const [, setIsPublishOpen] = useIsPublishDialogOpen();@@ -138,7 +137,7 @@ export const Menu = ({ config, publish }: MenuProps) => {<DropdownMenuItemcss={menuItemCss}onSelect={() => {- navigate(config.dashboardPath);+ navigate(dashboardPath());}}>Dashboarddiff --git a/apps/designer/app/designer/features/topbar/publish.tsx b/apps/designer/app/designer/features/topbar/publish.tsxindex 07c2f2877e..1317d37b29 100644--- a/apps/designer/app/designer/features/topbar/publish.tsx+++ b/apps/designer/app/designer/features/topbar/publish.tsx@@ -17,6 +17,7 @@ import {import { useIsPublishDialogOpen } from "../../shared/nano-states";import env from "~/shared/env";import type { Project } from "@webstudio-is/project";+import { restPublishPath } from "~/shared/router-utils";type PublishButtonProps = { project: Project };const getHost = () => {@@ -49,7 +50,7 @@ const Content = ({ project }: PublishButtonProps) => {event.preventDefault();}}>- <fetcher.Form method="post" action="/rest/publish">+ <fetcher.Form method="post" action={restPublishPath()}><Flex direction="column" gap="2">{url !== undefined && (<Linkdiff --git a/apps/designer/app/designer/features/topbar/topbar.tsx b/apps/designer/app/designer/features/topbar/topbar.tsxindex 2dc4289807..7ebf328289 100644--- a/apps/designer/app/designer/features/topbar/topbar.tsx+++ b/apps/designer/app/designer/features/topbar/topbar.tsx@@ -1,6 +1,5 @@import type { Publish } from "~/shared/pubsub";import { darkTheme, Flex, type CSS } from "@webstudio-is/design-system";-import type { Config } from "~/config";import { PreviewButton } from "./preview";import { ShareButton } from "./share";import { PublishButton } from "./publish";@@ -10,19 +9,12 @@ import { Breakpoints } from "../breakpoints";import type { Project } from "@webstudio-is/project";type TopbarProps = {- config: Config;css: CSS;project: Project;publish: Publish;previewUrl: string;};-export const Topbar = ({- config,- css,- project,- publish,- previewUrl,-}: TopbarProps) => {+export const Topbar = ({ css, project, publish, previewUrl }: TopbarProps) => {return (<FlexclassName={darkTheme}@@ -48,7 +40,7 @@ export const Topbar = ({...css,}}>- <Menu config={config} publish={publish} />+ <Menu publish={publish} /><Breakpoints publish={publish} /><Flexalign="center"diff --git a/apps/designer/app/designer/shared/assets/use-assets.ts b/apps/designer/app/designer/shared/assets/use-assets.tsindex e4d10fdff7..ba32d05c9b 100644--- a/apps/designer/app/designer/shared/assets/use-assets.ts+++ b/apps/designer/app/designer/shared/assets/use-assets.ts@@ -8,6 +8,7 @@ import {import { toast } from "@webstudio-is/design-system";import ObjectID from "bson-objectid";import { useMemo } from "react";+import { restAssetsPath } from "~/shared/router-utils";import { useAssets as useAssetsState, useProject } from "../nano-states";import { PreviewAsset } from "./types";@@ -62,7 +63,7 @@ export const useAssets = (type: AssetType) => {const { submit, Form } = useFetcher();const [assets, setAssets] = useAssetsState();const [project] = useProject();- const action = `/rest/assets/${project?.id}`;+ const action = project && restAssetsPath({ projectId: project.id });const handleDelete = (ids: Array<string>) => {const formData = new FormData();diff --git a/apps/designer/app/routes/$.tsx b/apps/designer/app/routes/$.tsxindex 726dda2135..bd78a6e56a 100644--- a/apps/designer/app/routes/$.tsx+++ b/apps/designer/app/routes/$.tsx@@ -7,13 +7,16 @@ import {import { useLoaderData } from "@remix-run/react";import { InstanceRoot, Root } from "@webstudio-is/react-sdk";import { loadCanvasData, type CanvasData } from "~/shared/db";-import config from "~/config";import { db } from "@webstudio-is/project/server";import env, { Env } from "~/env.server";import { sentryException } from "~/shared/sentry";import { Canvas } from "~/canvas";import { ErrorMessage } from "~/shared/error";-import { type BuildMode, getBuildParams } from "~/shared/router-utils";+import {+ type BuildMode,+ getBuildParams,+ dashboardPath,+} from "~/shared/router-utils";type Data =| (CanvasData & { env: Env; mode: BuildMode })@@ -34,7 +37,7 @@ export const loader: LoaderFunction = async ({const buildParams = getBuildParams(request);if (buildParams === undefined) {- return redirect(config.dashboardPath);+ return redirect(dashboardPath());}const { mode, pathname } = buildParams;diff --git a/apps/designer/app/routes/auth/dev.tsx b/apps/designer/app/routes/auth/dev.tsxindex c2791ca2a6..3d2e77bc51 100644--- a/apps/designer/app/routes/auth/dev.tsx+++ b/apps/designer/app/routes/auth/dev.tsx@@ -1,6 +1,6 @@import { ActionFunction, redirect } from "@remix-run/node";-import config from "~/config";import { authenticator } from "~/services/auth.server";+import { dashboardPath, loginPath } from "~/shared/router-utils";import { AUTH_PROVIDERS } from "~/shared/session";export default function Dev() {@@ -10,7 +10,7 @@ export default function Dev() {export const action: ActionFunction = async ({ request }) => {try {return await authenticator.authenticate("dev", request, {- successRedirect: config.dashboardPath,+ successRedirect: dashboardPath(),throwOnError: true,});} catch (error: unknown) {@@ -18,9 +18,7 @@ export const action: ActionFunction = async ({ request }) => {if (error instanceof Response) return error;if (error instanceof Error) {return redirect(- `${config.loginPath}?error=${AUTH_PROVIDERS.LOGIN_DEV}&message=${- error?.message || ""- }`+ loginPath({ error: AUTH_PROVIDERS.LOGIN_DEV, message: error?.message }));}}diff --git a/apps/designer/app/routes/auth/github.tsx b/apps/designer/app/routes/auth/github.tsxindex 2939ff7252..829b04c8da 100644--- a/apps/designer/app/routes/auth/github.tsx+++ b/apps/designer/app/routes/auth/github.tsx@@ -1,6 +1,6 @@import { ActionFunction, redirect } from "@remix-run/node";-import config from "~/config";import { authenticator } from "~/services/auth.server";+import { dashboardPath, loginPath } from "~/shared/router-utils";import { sentryException } from "~/shared/sentry";import { AUTH_PROVIDERS } from "~/shared/session";@@ -11,7 +11,7 @@ export default function GH() {export const action: ActionFunction = async ({ request }) => {try {return await authenticator.authenticate("github", request, {- successRedirect: config.dashboardPath,+ successRedirect: dashboardPath(),throwOnError: true,});} catch (error: unknown) {@@ -25,9 +25,10 @@ export const action: ActionFunction = async ({ request }) => {},});return redirect(- `${config.loginPath}?error=${AUTH_PROVIDERS.LOGIN_GITHUB}&message=${- error?.message || ""- }`+ loginPath({+ error: AUTH_PROVIDERS.LOGIN_GITHUB,+ message: error?.message,+ }));}}diff --git a/apps/designer/app/routes/auth/github/callback.tsx b/apps/designer/app/routes/auth/github/callback.tsxindex 0314b96268..4dcbf0e4ad 100644--- a/apps/designer/app/routes/auth/github/callback.tsx+++ b/apps/designer/app/routes/auth/github/callback.tsx@@ -1,6 +1,6 @@import { LoaderFunction, redirect } from "@remix-run/node";-import config from "~/config";import { authenticator } from "~/services/auth.server";+import { dashboardPath, loginPath } from "~/shared/router-utils";import { AUTH_PROVIDERS } from "~/shared/session";export const loader: LoaderFunction = async ({ request }) => {@@ -9,13 +9,14 @@ export const loader: LoaderFunction = async ({ request }) => {const error_description = url.searchParams.get("error_description");if (error) {return redirect(- `${config.loginPath}?error=${AUTH_PROVIDERS.LOGIN_GITHUB}&message=${- error_description || error- }`+ loginPath({+ error: AUTH_PROVIDERS.LOGIN_GITHUB,+ message: error_description || error,+ }));}return authenticator.authenticate("github", request, {- successRedirect: config.dashboardPath,- failureRedirect: config.loginPath,+ successRedirect: dashboardPath(),+ failureRedirect: loginPath({}),});};diff --git a/apps/designer/app/routes/auth/google.tsx b/apps/designer/app/routes/auth/google.tsxindex 962216580c..8ffc35f693 100644--- a/apps/designer/app/routes/auth/google.tsx+++ b/apps/designer/app/routes/auth/google.tsx@@ -1,6 +1,6 @@import { ActionFunction, LoaderFunction, redirect } from "@remix-run/node";-import config from "~/config";import { authenticator } from "~/services/auth.server";+import { dashboardPath, loginPath } from "~/shared/router-utils";import { sentryException } from "~/shared/sentry";import { AUTH_PROVIDERS } from "~/shared/session";@@ -13,7 +13,7 @@ export const loader: LoaderFunction = () => redirect("/login");export const action: ActionFunction = async ({ request }) => {try {return await authenticator.authenticate("google", request, {- successRedirect: config.dashboardPath,+ successRedirect: dashboardPath(),throwOnError: true,});} catch (error: unknown) {@@ -27,9 +27,10 @@ export const action: ActionFunction = async ({ request }) => {},});return redirect(- `${config.loginPath}?error=${AUTH_PROVIDERS.LOGIN_GOOGLE}&message=${- error?.message || ""- }`+ loginPath({+ error: AUTH_PROVIDERS.LOGIN_GOOGLE,+ message: error?.message,+ }));}}diff --git a/apps/designer/app/routes/auth/google/callback.tsx b/apps/designer/app/routes/auth/google/callback.tsxindex 5eaf1b129a..54b4713352 100644--- a/apps/designer/app/routes/auth/google/callback.tsx+++ b/apps/designer/app/routes/auth/google/callback.tsx@@ -1,10 +1,10 @@import { LoaderFunction } from "@remix-run/node";-import config from "~/config";import { authenticator } from "~/services/auth.server";+import { dashboardPath, loginPath } from "~/shared/router-utils";export const loader: LoaderFunction = async ({ request }) => {return authenticator.authenticate("google", request, {- successRedirect: config.dashboardPath,- failureRedirect: config.loginPath,+ successRedirect: dashboardPath(),+ failureRedirect: loginPath({}),});};diff --git a/apps/designer/app/routes/dashboard/index.tsx b/apps/designer/app/routes/dashboard/index.tsxindex f23b33b74c..7e514a5ae8 100644--- a/apps/designer/app/routes/dashboard/index.tsx+++ b/apps/designer/app/routes/dashboard/index.tsx@@ -7,11 +7,11 @@ import {} from "@remix-run/node";import { Dashboard, links } from "~/dashboard";import { db } from "@webstudio-is/project/server";-import config, { type Config } from "~/config";import { ensureUserCookie } from "~/shared/session";import { authenticator } from "~/services/auth.server";import { zfd } from "zod-form-data";import { type Project, User } from "@webstudio-is/prisma-client";+import { designerPath, loginPath } from "~/shared/router-utils";export { links };const schema = zfd.formData({@@ -19,7 +19,6 @@ const schema = zfd.formData({});type Data = {- config: Config;projects: Array<Project>;user: User;};@@ -34,7 +33,7 @@ export const action: ActionFunction = async ({ request }) => {title,userId: authenticatedUser?.id || userId,});- return redirect(`${config.designerPath}/${project?.id}`, { headers });+ return redirect(designerPath({ projectId: project.id }), { headers });} catch (error) {if (error instanceof Error) {return { errors: error.message };@@ -46,17 +45,17 @@ export const action: ActionFunction = async ({ request }) => {export const loader: LoaderFunction = async ({ request }) => {const user = await authenticator.isAuthenticated(request);if (!user) {- return redirect(config.loginPath);+ return redirect(loginPath({}));}const { headers } = await ensureUserCookie(request);const projects = await db.project.loadManyByUserId(user.id);- return json({ config, projects, user }, headers);+ return json({ projects, user }, headers);};const DashboardRoute = () => {- const { config, projects, user } = useLoaderData<Data>();+ const { projects, user } = useLoaderData<Data>();- return <Dashboard config={config} user={user} projects={projects} />;+ return <Dashboard user={user} projects={projects} />;};export default DashboardRoute;diff --git a/apps/designer/app/routes/designer/$projectId.tsx b/apps/designer/app/routes/designer/$projectId.tsxindex 94bea5cf36..6f2604c951 100644--- a/apps/designer/app/routes/designer/$projectId.tsx+++ b/apps/designer/app/routes/designer/$projectId.tsx@@ -2,7 +2,6 @@ import { useLoaderData } from "@remix-run/react";import { LoaderFunction } from "@remix-run/node";import { type DesignerProps, Designer, links } from "~/designer";import { db } from "@webstudio-is/project/server";-import config from "~/config";import { ErrorMessage } from "~/shared/error";import { sentryException } from "~/shared/sentry";import { getBuildOrigin } from "~/shared/router-utils";@@ -30,7 +29,6 @@ export const loader: LoaderFunction = async ({const devBuild = await db.build.loadByProjectId(project.id, "dev");return {- config,project,pages: devBuild.pages,pageId: pageIdParam || devBuild.pages.homePage.id,diff --git a/apps/designer/app/routes/login/index.tsx b/apps/designer/app/routes/login/index.tsxindex ffb6e11207..b83b5361eb 100644--- a/apps/designer/app/routes/login/index.tsx+++ b/apps/designer/app/routes/login/index.tsx@@ -1,18 +1,18 @@import { LoaderFunction, redirect } from "@remix-run/node";import { authenticator } from "~/services/auth.server";-import config from "~/config";import env from "~/env.server";import { Login, links } from "~/auth";import { useLoginErrorMessage } from "~/shared/session";+import { dashboardPath } from "~/shared/router-utils";export { links };export const loader: LoaderFunction = async ({ request }) => {const user = await authenticator.isAuthenticated(request);if (user) {- return redirect(config.dashboardPath);+ return redirect(dashboardPath());}return {isDevLogin: process.env.DEV_LOGIN === "true",diff --git a/apps/designer/app/routes/logout.tsx b/apps/designer/app/routes/logout.tsxindex b1ab7ebb2d..d7f80db096 100644--- a/apps/designer/app/routes/logout.tsx+++ b/apps/designer/app/routes/logout.tsx@@ -1,11 +1,11 @@import { ActionFunction } from "@remix-run/node";-import config from "~/config";import { authenticator } from "~/services/auth.server";+import { loginPath } from "~/shared/router-utils";export default function Logout() {return null;}export const loader: ActionFunction = async ({ request }) => {- await authenticator.logout(request, { redirectTo: config.loginPath });+ await authenticator.logout(request, { redirectTo: loginPath({}) });};diff --git a/apps/designer/app/routes/rest/project/clone.$domain.ts b/apps/designer/app/routes/rest/project/clone.$domain.tsindex a649a323c5..1a55ef20e7 100644--- a/apps/designer/app/routes/rest/project/clone.$domain.ts+++ b/apps/designer/app/routes/rest/project/clone.$domain.ts@@ -4,8 +4,8 @@ import { db as projectDb } from "@webstudio-is/project/server";import { type Project } from "@webstudio-is/project";import * as userDb from "~/shared/db";import { ensureUserCookie } from "~/shared/session";-import config from "~/config";import { authenticator } from "~/services/auth.server";+import { designerPath } from "~/shared/router-utils";const ensureProject = async ({userId,@@ -40,7 +40,7 @@ export const loader: LoaderFunction = async ({ request, params }) => {userId,domain: params.domain,});- return redirect(`${config.designerPath}/${project?.id}`, { headers });+ return redirect(designerPath({ projectId: project.id }), { headers });} catch (error: unknown) {if (error instanceof Error) {return { errors: error.message };diff --git a/apps/designer/app/services/auth.server.ts b/apps/designer/app/services/auth.server.tsindex 23690cdc09..287d949330 100644--- a/apps/designer/app/services/auth.server.ts+++ b/apps/designer/app/services/auth.server.ts@@ -3,17 +3,16 @@ import { Authenticator } from "remix-auth";import { FormStrategy } from "remix-auth-form";import { GitHubStrategy, type GitHubProfile } from "remix-auth-github";import { GoogleStrategy, type GoogleProfile } from "remix-auth-google";-import config from "~/config";import * as db from "~/shared/db";import { sessionStorage } from "~/services/session.server";import { sentryException } from "~/shared/sentry";import { AUTH_PROVIDERS } from "~/shared/session";+import { authCallbackPath } from "~/shared/router-utils";-const url = `${+const url =process.env.DEPLOYMENT_ENVIRONMENT === "production"? process.env.DEPLOYMENT_URL- : `http://localhost:${process.env.PORT || 3000}`-}${config.authPath}`;+ : `http://localhost:${process.env.PORT || 3000}`;const strategyCallback = async ({profile,@@ -47,7 +46,7 @@ if (process.env.GH_CLIENT_ID && process.env.GH_CLIENT_SECRET) {{clientID: process.env.GH_CLIENT_ID,clientSecret: process.env.GH_CLIENT_SECRET,- callbackURL: `${url}${config.githubCallbackPath}`,+ callbackURL: `${url}${authCallbackPath({ provider: "github" })}`,},strategyCallback);@@ -59,7 +58,7 @@ if (process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET) {{clientID: process.env.GOOGLE_CLIENT_ID,clientSecret: process.env.GOOGLE_CLIENT_SECRET,- callbackURL: `${url}${config.googleCallbackPath}`,+ callbackURL: `${url}${authCallbackPath({ provider: "google" })}`,},strategyCallback);diff --git a/apps/designer/app/shared/router-utils/build-params.ts b/apps/designer/app/shared/router-utils/build-params.tsindex 37694a3c6f..33f9c8f7b8 100644--- a/apps/designer/app/shared/router-utils/build-params.ts+++ b/apps/designer/app/shared/router-utils/build-params.ts@@ -1,3 +1,6 @@+// These are the utils for manipulating "build" params.+// "Build" means user generated content — what user builds.+export type BuildMode = "edit" | "preview" | "published";const modes = ["edit", "preview", "published"] as BuildMode[];const getMode = (url: URL): BuildMode => {diff --git a/apps/designer/app/shared/router-utils/index.ts b/apps/designer/app/shared/router-utils/index.tsindex 9eb5302fd6..26eef7723f 100644--- a/apps/designer/app/shared/router-utils/index.ts+++ b/apps/designer/app/shared/router-utils/index.ts@@ -1 +1,2 @@export * from "./build-params";+export * from "./path-utils";diff --git a/apps/designer/app/shared/router-utils/path-utils.ts b/apps/designer/app/shared/router-utils/path-utils.tsnew file mode 100644index 0000000000..9ee983ae14--- /dev/null+++ b/apps/designer/app/shared/router-utils/path-utils.ts@@ -0,0 +1,85 @@+import { AUTH_PROVIDERS } from "~/shared/session";+import type { Page, Project } from "@webstudio-is/project";+import type { BuildMode } from "./build-params";+import type { ThemeSetting } from "~/shared/theme";+import env from "~/shared/env";++const searchParams = (params: Record<string, string | undefined | null>) => {+ const searchParams = new URLSearchParams();+ for (const [key, value] of Object.entries(params)) {+ if (typeof value === "string") {+ searchParams.set(key, value);+ }+ }+ const asString = searchParams.toString();+ return asString === "" ? "" : `?${asString}`;+};++export const designerPath = ({+ projectId,+ pageId,+}: {+ projectId: string;+ pageId?: string;+}) => `/designer/${projectId}${searchParams({ pageId })}`;++export const dashboardPath = () => "/dashboard";++export const loginPath = (params: {+ error?: typeof AUTH_PROVIDERS[keyof typeof AUTH_PROVIDERS];+ message?: string;+}) => `/login${searchParams(params)}`;++export const logoutPath = () => "/logout";++export const authCallbackPath = ({+ provider,+}: {+ provider: "google" | "github";+}) => `/auth/${provider}/callback`;++export const authPath = ({+ provider,+}: {+ provider: "google" | "github" | "dev";+}) => `/auth/${provider}`;++export const restPagesPath = ({ projectId }: { projectId: string }) =>+ `/rest/pages/${projectId}`;++export const restAssetsPath = ({ projectId }: { projectId: string }) =>+ `/rest/assets/${projectId}`;++export const restThemePath = ({ setting }: { setting: ThemeSetting }) =>+ `/rest/theme/${setting}`;++export const restPatchPath = () => "/rest/patch";++export const restPublishPath = () => "/rest/publish";++export const getBuildUrl = ({+ buildOrigin,+ project,+ page,+ mode,+}: {+ buildOrigin: string;+ project: Project;+ page: Page;+ mode?: BuildMode;+}) => {+ const url = new URL(buildOrigin);+ url.pathname = page.path;++ if (env.BUILD_REQUIRE_SUBDOMAIN) {+ url.host = `${project.domain}.${url.host}`;+ } else {+ url.searchParams.set("projectId", project.id);+ }++ if (mode) {+ url.searchParams.set("mode", mode);+ }++ return url.toString();+};diff --git a/apps/designer/app/shared/session/use-login-error-message.ts b/apps/designer/app/shared/session/use-login-error-message.tsindex f0f120217f..4d81d487d1 100644--- a/apps/designer/app/shared/session/use-login-error-message.ts+++ b/apps/designer/app/shared/session/use-login-error-message.ts@@ -6,7 +6,7 @@ export const AUTH_PROVIDERS = {LOGIN_DEV: "login_dev",LOGIN_GITHUB: "login_github",LOGIN_GOOGLE: "login_google",-};+} as const;export const LOGIN_ERROR_MESSAGES = {[AUTH_PROVIDERS.LOGIN_DEV]: "There has been an issue logging you in with dev",diff --git a/apps/designer/app/shared/theme/theme.ts b/apps/designer/app/shared/theme/theme.tsindex 577df22b1c..411225e8ff 100644--- a/apps/designer/app/shared/theme/theme.ts+++ b/apps/designer/app/shared/theme/theme.ts@@ -1,5 +1,6 @@import { useLoaderData } from "@remix-run/react";import { darkTheme } from "@webstudio-is/design-system";+import { restThemePath } from "~/shared/router-utils";import type { ColorScheme, ThemeSetting } from "./types";// User selected theme setting.@@ -57,7 +58,7 @@ const renderThemeProps = () => {export const setThemeSetting = (nextSetting: ThemeSetting) => {setting = nextSetting;renderThemeProps();- fetch(`/rest/theme/${setting}`);+ fetch(restThemePath({ setting }));};/**