Skip to main content
HydroGo
FrontendsSSR frontends: SvelteKit, Next.js, Astro

SSR frontends: SvelteKit, Next.js, Astro

HydroGo ships no public frontend. Build yours in any framework, put it behind HydroGo with the external storefront bridge, and read theme tokens from the API.

HydroGo is a headless backend: it serves JSON and an admin panel, and you write the public site. There is no bundled frontend starter in HydroGo Core. Two setups work: run your frontend as a separate service that calls the API, or let HydroGo front it with the external storefront bridge. Publishing content or switching a theme in the admin takes effect on the next request without rebuilding.

External storefront bridge

With storefront.external.enabled: true, HydroGo serves your frontend's static client assets directly (precompressed, hashed assets cached as immutable, HTML always revalidated) and proxies dynamic SSR requests to your framework's server. If command is set, HydroGo also starts and supervises that process.

config.yaml
storefront:
  external:
    enabled: true
    command: "node build/index.js"   # optional: HydroGo supervises this child process
    dir: "frontend"                  # working directory of the command
    upstream: "http://127.0.0.1:3000"
    static_dir: "frontend/build/client"
    env:
      HYDRO_API_ORIGIN: "http://127.0.0.1:8080"
      PORT: "3000"
KeyMeaning
enabledTurns the bridge on.
upstreamWhere the SSR server listens. Dynamic requests are proxied here.
static_dirBuilt client assets served directly by HydroGo.
command, dirOptional. Start the SSR server as a supervised child process, in dir.
env, env_fileEnvironment passed to the child process.
static_cache_secondsBrowser cache lifetime for static files that are neither hashed assets nor HTML, for example product photos. Default 3600.

When a separate storefront shares the domain with HydroGo, route every HydroGo path to HydroGo. See Caching and webhooks for cache invalidation.

Selectable storefront themes

Storefronts can read the active theme, validated CSS design tokens, and live preview overrides (?theme_preview=<id>) from GET /api/v1/site/themes, and convert them into CSS custom properties with themeTokensToStyleString from @hydrohq/client:

TS
import { themeTokensToStyleString } from '@hydrohq/client';

const res = await fetch(`${HYDRO_API_ORIGIN}/api/v1/site/themes`);
const { data } = await res.json();
// Apply data.tokens as inline CSS variables (--hydro-bg, --hydro-accent, ...)
const rootStyle = themeTokensToStyleString(data.tokens);

Quick setup with AI assistants

Every project created with hydro new includes an AGENTS.md file describing your content-types/*.yaml, API endpoints, and CSRF rules. You can also feed https://hydrogo.dev/llms-full.txt or connect the HydroGo MCP server directly to your AI editor to scaffold your frontend.

VariableMeaning
HYDRO_API_ORIGINWhere HydroGo runs. Server-side only, never sent to the browser.
PUBLIC_SITE_ORIGINPublic URL of this frontend, used for canonical links and the sitemap.
HYDRO_LOCALELocale requested from the API (default en).

Mapping API errors to HTTP statuses

A 404 from HydroGo should become a real 404 for visitors and crawlers; other failures should become a 502 that carries the request id. In SvelteKit:

hydro.ts
// src/lib/server/hydro.ts
import { error } from '@sveltejs/kit';
import { HydroGoError } from '@hydrohq/client';

export function toHttpError(err: unknown): never {
  if (err instanceof HydroGoError) {
    if (err.status === 404) error(404, 'Not found');
    error(502, `Content API error${err.requestId ? ` (request ${err.requestId})` : ''}`);
  }
  error(502, 'Content API unreachable');
}

Using another framework

Nothing here is specific to SvelteKit. In Next.js, Nuxt, Astro, Remix or Express, fetch from server-side code on each request (or with a short revalidate window), render HTML and set cache headers as described in Caching and webhooks.

TS
// Next.js (app router): revalidate every 30 seconds
import DOMPurify from 'isomorphic-dompurify';

export default async function Page({ params }: { params: { slug: string } }) {
  const res = await fetch(
    `${process.env.HYDRO_API_ORIGIN}/api/v1/pages/by-slug?locale=en&slug=${encodeURIComponent(params.slug)}`,
    { next: { revalidate: 30 } },
  );
  const { data } = await res.json();
  return <article dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(data.body) }} />;
}