> For the complete documentation index, see [llms.txt](https://docs.ecwid.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ecwid.com/site-themes/develop-site-themes/sections/server.md).

# Server

The `server.ts` file is the server-side rendering (SSR) entry point for your section. It renders your Vue component to HTML on the server, producing the initial markup that is sent to the browser before JavaScript loads.

### How It Works <a href="#how-it-works" id="how-it-works"></a>

During a build or server request, the SSR entry point:

1. Initializes a Vue app instance with your section component
2. Receives the context (store info, global design) and data (content, design values)
3. Renders the component to an HTML string using Vue's server renderer
4. Returns the HTML along with the serialized state for client-side hydration

This ensures the section is visible immediately on page load, before any JavaScript executes.

### Usage <a href="#usage" id="usage"></a>

```typescript
// server.ts
import { createVueServerApp } from '@lightspeed/crane-api';
import Section from './Section.vue';
import type { Content, Design } from './type';

export default createVueServerApp<Content, Design>(Section);
```

The generic parameters `<Content, Design>` provide type safety for the data passed during rendering.

### Extensions <a href="#extensions" id="extensions"></a>

`createVueServerApp` accepts an optional second argument for hooking into the app lifecycle:

```typescript
createVueServerApp<Content, Design>(Section, {
  init(app) {
    // Called after the Vue app is created, before rendering.
    // Use this to register plugins, directives, or global components.
  },
  render(app, context, data) {
    // Called just before the component renders to HTML.
    // Access the context (store info, global design) and data (content, design).
  },
});
```

All extension callbacks are optional.

{% hint style="info" %}
For most sections, the basic usage without extensions is sufficient. Extensions are useful when you need to register Vue plugins or perform setup before the render pass.
{% endhint %}

### SSR Considerations <a href="#ssr-considerations" id="ssr-considerations"></a>

Since server-side rendering runs in Node.js, browser APIs are not available:

* **No `window`, `document`, or `navigator`** — guard any browser-specific code with `typeof window !== 'undefined'` or move it to `onMounted` in your Vue component
* **No event listeners** — attach them in `onMounted` on the client side
* **No DOM measurements** — use safe defaults during SSR and update in `onMounted`

See [Composables](https://docs.ecwid.com/site-themes/develop-site-themes/sections/ui-helpers/composables.md#best-practices) for patterns.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ecwid.com/site-themes/develop-site-themes/sections/server.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
